I am trying to do a user recipe from RecipesBase.jl but I seem to not get the idea how Recipes work I fear.
Context.
I would like to do something that I thought was quite easy. Given the M=Sphere(2)
from Manifolds.jl and a set of points (maybe just pts=[ [ 1.0, 0.0, 0.0], [0.0, 1.0, 0.0] ]
I would like to be able to write
scene = plot(M,pts)
to draw a sphere and two markers where these points are,
Best would be that for the scene I could also add things using plot!(scene, M, pts2)
for a second set of points.
Here’s my current approach – and I can’t find what I am doing wrong, I fear I have a conceptual problem with recipes still.
Here’s my current (nonworking) MWE
using Manifolds, Plots, RecipesBase
@recipe function f(
M::Sphere{2},
pts::AbstractVector{T};
wireframe_lat=33,
wireframe_lon=33,
) where {T}
show_axis --> false
φ_range = range(0,stop=2*π,length=wireframe_lon)
λ_range = range(0,stop=π,length=wireframe_lat)
x = [cos(φ) * sin(λ) for φ ∈ φ_range, λ ∈ λ_range]
y = [sin(φ) * sin(λ) for φ ∈ φ_range, λ ∈ λ_range]
z = [cos(λ) for φ ∈ φ_range, λ ∈ λ_range]
scene = plot() # I assume this should be the global plot? Wherefrom?
wireframe!(scene, x, y, z)
seriestype --> :scatter
return [p[1] for p ∈ pts], [p[2] for p ∈ pts], [p[3] for p ∈ pts]
end
M = Sphere(2)
pts = [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0] ]
plot(M, pts)
and I also was not able to find something similar on the net.
How do I add something to a plot, when usually the recipe only returns x, y, z
and I can’t seem to access the plot to add the sphere? It just plots the two points.