-
-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extending recipes with new types doesn't always work #3988
Comments
function Makie.convert_arguments(P::Makie.PointBased, f::Function)
x = ...
y = f.(x)
return convert_arguments(P, x, y)
end |
How to make |
It's not. The main point of You also need to be careful with cyclical updates when doing things based on limits, because limits are based on positional data. https://github.com/MakieOrg/Makie.jl/blob/master/src/basic_recipes/hvlines.jl for example discards the dependent dimension in |
Ok, and that's what I want, and that's what I implemented in a hacky way (by overriding The "proper" way to do such a recipe would be to define function Makie.plot!(p::Lines{<:Function})
func = p[1]
limits = Makie.projview_to_2d_limits(p)
points = lift(p, func, limits) do func, limits
xs = range(first.(extrema(limits))..., length = 400)
Makie.Point2d.(xs, func.(xs))
end
lines!(p, p.attributes, points)
return p
end That's what I'm trying to do, but it doesn't work. |
You mean:
Conversions for primitive plot types are checked now, so you can't do this anymore. I think you'll need a new recipe for this: @recipe(InfLines, f) do scene
return Makie.default_theme(Lines, scene)
end
function Makie.plot!(p::InfLines)
func = p.f
limits = Makie.projview_to_2d_limits(p)
points = lift(p, func, limits) do func, limits
xs = range(first.(extrema(limits))..., length=400)
Makie.Point2d.(xs, func.(xs))
end
lines!(p, p.attributes, points)
return p
end
inflines(sin, color = :red, linewidth = 2) It feels better this way, since strictly speaking you're pirating You could also do: function Makie.plot!(p::Plot{plot, Tuple{F}}) where F <: Function
func = p[1]
limits = Makie.projview_to_2d_limits(p)
points = lift(p, func, limits) do func, limits
xs = range(first.(extrema(limits))..., length=400)
Makie.Point2d.(xs, func.(xs))
end
lines!(p, p.attributes, points)
return p
end
plot(sin, color = :red, linewidth = 2) Not sure if I like that though... Maybe |
Yeah I kinda hoped to avoid defining new plot types like this... Even for 1d, one reasonably needs at least
That's pretty benign piracy, adding new functionality and not changing existing one. Longer term I hoped that such a recipe is possible and can be upstreamed to Makie :) Unfortunately currently it doesn't seem possible in a clean way, so I'll just keep the hacky but working implementation in MakieExtra. |
More generally, can this check be avoided/overridden?
If a |
We've been fighting with ill defined plot objects for a long time now, and the fact, that you can't rely on Sadly, Maybe we can find a way to treat I guess we can find some better ways to make this possible, but it's certainly more complicated than it looks on first sight, when knowing all the constraints that go into the design decision. |
Couldn't this specific problem be solved with a recipe that internally uses whatever plot type you pass to it? Probably would be a little tricky to set it up performantly but then at least you wouldn't need one recipe per function. I like the separate-recipe route better than making So something like
|
Yeah, that's what I meant to propose with |
So, this tutorial https://docs.makie.org/stable/tutorials/wrap-existing-recipe is outdated, right? (specifically the last section) That's where I got the idea that overloading |
These attributes aren't special to
For this specific case, probably this could be fine... Although, a very unusual interface compared to every other plotting function in Makie.
Can't this be solved with |
Trying to make a proper recipe for stuff like
lines(function)
that plot the function over the whole axis x-range. Current hacky implementation at https://github.com/JuliaAPlavin/MakieExtra.jl/blob/master/src/axisfunction.jl.However, following the docs and defining required functions I still get a conversion error:
How to define it properly?
The text was updated successfully, but these errors were encountered: