I am starting to really appreciate how RecipesBase works, now that I slowly understand the scheme. Maybe for now this is limited to user recipes, but nevertheless, really neat!
Currently I have one point left, where I am reproducing code, that I would like to only do once. Consider the following example, which I tried to get minimal
using Plots, RecipesBase, Colors
gr()
struct myType
d::Int
s::Int
end
@recipe function f(m::myType)
@series begin
seriestype := surface
fillcolor := RGBA(0.0, 0.5, 1.0, 1.0)
legend := :none
return [-m.d,-m.d,m.d,m.d,-m.d], [-m.d,m.d,m.d,-m.d,-m.d], [0,0,0,0,0]
end
end
@recipe function f(m::myType, pts::AbstractVector{T}) where {T}
@series begin
seriestype := surface
fillcolor := RGBA(0.0, 0.5, 1.0, 1.0)
legend := :none
return [-m.d,-m.d,m.d,m.d,-m.d], [-m.d,m.d,m.d,-m.d,-m.d], [0,0,0,0,0]
end
return [p[1] for p ∈ pts], [p[2] for p ∈ pts], [p[3] for p ∈ pts]
end
D = myType(3,2)
scene1plot(D)
scene2 = plot(D, [[1,1,1],[2,2,2]])
Then scene 2 looks like
Which is (up to my laziness to remove the colormap) what I would like to have.
-
As you can see the inner
@series
appears twice in the code, or in other words I would like to just use the first recipe as part of the second. Could that be done? -
I would like to avoid redrawing this first recipe in
plot!
cases, i.e. only draw the surface once for the first appearance of such a user recipe. Is that possible? -
I would like to make the inner
@series
depend onxlim
/ylim
(i.e. make the surface similarly large) can I somehow check what the user provided for these values within the recipe?
For context: The first type introduces a context for the data pts
in my application see for example Hyperbolic space · Manifolds.jl for a first sketch of what I aim to do.