From this question, I understand that a type recipe is for plotting a specific type with a wider range of signatures. However, I cannot add an hline
in the figure within a recipe.
using RecipesBase: @recipe, @series
struct MyWrapper
v::Vector
end
@recipe function f(::Type{MyWrapper}, mw::MyWrapper)
@series begin
seriestype --> :hline
seriescolor := :black
z_order --> :back
zeros(1)
end
return mw.v
end
However, I cannot plot anything from it:
x = MyWrapper(cumsum(rand(10)))
plot(x)
julia> plot(1:10, x)
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: BoundsError: attempt to access 1-element Vector{Float64} at index [1:10]
Stacktrace:
[1] throw_boundserror(A::Vector{Float64}, I::Tuple{UnitRange{Int64}})
@ Base ./abstractarray.jl:703
[2] checkbounds
@ ./abstractarray.jl:668 [inlined]
[3] getindex(A::Vector{Float64}, I::UnitRange{Int64})
@ Base ./array.jl:930
[4] gr_draw_segments(series::Plots.Series, x::UnitRange{Int64}, y::Vector{Float64}, z::Nothing, fillrange::Nothing, clims::Tuple{Float64, Float64})
@ Plots ~/.julia/packages/Plots/nuwp4/src/backends/gr.jl:1789
[5] gr_add_series(sp::Plots.Subplot{Plots.GRBackend}, series::Plots.Series)
@ Plots ~/.julia/packages/Plots/nuwp4/src/backends/gr.jl:1706
[6] gr_display(sp::Plots.Subplot{Plots.GRBackend}, w::Measures.AbsoluteLength, h::Measures.AbsoluteLength, vp_canvas::Plots.GRViewport{Float64})
@ Plots ~/.julia/packages/Plots/nuwp4/src/backends/gr.jl:956
[7] (::Plots.var"#526#527"{Int64, Int64, Plots.GRViewport{Float64}})(sp::Plots.Subplot{Plots.GRBackend})
@ Plots ~/.julia/packages/Plots/nuwp4/src/backends/gr.jl:680
[8] foreach(f::Plots.var"#526#527"{Int64, Int64, Plots.GRViewport{Float64}}, itr::Vector{Plots.Subplot})
@ Base ./abstractarray.jl:2774
[9] gr_display(plt::Plots.Plot{Plots.GRBackend}, dpi_factor::Int64)
@ Plots ~/.julia/packages/Plots/nuwp4/src/backends/gr.jl:680
[10] gr_display
@ ~/.julia/packages/Plots/nuwp4/src/backends/gr.jl:650 [inlined]
[11] #572
@ ~/.julia/packages/Plots/nuwp4/src/backends/gr.jl:2044 [inlined]
[12] withenv(::Plots.var"#572#574"{Plots.Plot{Plots.GRBackend}}, ::Pair{String, String}, ::Vararg{Pair{String}})
@ Base ./env.jl:172
[13] _display(plt::Plots.Plot{Plots.GRBackend})
@ Plots ~/.julia/packages/Plots/nuwp4/src/backends/gr.jl:2043
[14] display(#unused#::Plots.PlotsDisplay, plt::Plots.Plot{Plots.GRBackend})
@ Plots ~/.julia/packages/Plots/nuwp4/src/output.jl:174
[15] display(x::Any)
@ Base.Multimedia ./multimedia.jl:328
[16] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
@ REPL ~/.asdf/installs/julia/1.8.5/share/julia/stdlib/v1.8/REPL/src/REPL.jl:0
[17] (::REPL.var"#45#46"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
@ REPL ~/.asdf/installs/julia/1.8.5/share/julia/stdlib/v1.8/REPL/src/REPL.jl:278
[18] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
@ REPL ~/.asdf/installs/julia/1.8.5/share/julia/stdlib/v1.8/REPL/src/REPL.jl:521
[19] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
@ REPL ~/.asdf/installs/julia/1.8.5/share/julia/stdlib/v1.8/REPL/src/REPL.jl:276
[20] (::REPL.var"#do_respond#66"{Bool, Bool, REPL.var"#77#87"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
@ REPL ~/.asdf/installs/julia/1.8.5/share/julia/stdlib/v1.8/REPL/src/REPL.jl:857
[21] #invokelatest#2
@ ./essentials.jl:729 [inlined]
[22] invokelatest
@ ./essentials.jl:726 [inlined]
[23] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
@ REPL.LineEdit ~/.asdf/installs/julia/1.8.5/share/julia/stdlib/v1.8/REPL/src/LineEdit.jl:2510
[24] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
@ REPL ~/.asdf/installs/julia/1.8.5/share/julia/stdlib/v1.8/REPL/src/REPL.jl:1248
[25] (::REPL.var"#49#54"{REPL.LineEditREPL, REPL.REPLBackendRef})()
@ REPL ./task.jl:484