Stefan, after studying PlotlyJS
a bit and iterating a bit more, I think I have a solution you will like. The only change necessary in your code is to replace using PlotlyJS
by the following:
function stem(; x=nothing, y, kwargs...)
if isnothing(x)
return PlotlyBase.stem(; y = n2v(y), kwargs...)
else
return PlotlyBase.stem(; x = n2v(x), y = n2v(y), kwargs...)
end
end
n2v(x::Number) = [x]
n2v(x::AbstractVector) = isone(length(x)) ? x : throw(ArgumentError("length must be 1"))
using PlotlyJS
It is important that the definition of stem
above precede using PlotlyJS
. Now you can call stem
exactly as before, except that the x
and y
keyword arguments can be either numbers or single-element vectors. For example, suppose you forget to surround the y
argument with braces:
julia> num_ = round(Int, 0.01 * 24999876)
249999
julia> stem_frequ_Hall_assumed = stem(; x = [0.6*num_], y = 1, name = "f_Hall(assumed)", yaxis="y2")
scatter with fields error_y, hoverinfo, marker, mode, name, text, type, x, y, and yaxis
If we examine the fields we see that y
is a 1-element vector as desired:
julia> stem_frequ_Hall_assumed.fields
Dict{Symbol, Any} with 10 entries:
:x => [1.49999e5]
:mode => "markers"
:y => [1]
:type => "scatter"
:name => "f_Hall(assumed)"
:hoverinfo => "text"
:error_y => Dict{Symbol, Any}(:color=>"grey", :width=>0, :symmetric=>false, :type=>"data", :visible=>true, :array=>[0], :thickness=>1, :arrayminus=>[1])
:text => [1]
:yaxis => "y2"
:marker => Dict{Any, Any}(:size=>10)
It took me a while to get to this solution–for me that is the nature of developing software. It’s a process of iterative refinement. Usually, the refinements are completed out of public view (like making sausage
).