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
Keyword arguments in convert_arguments
?
#837
Comments
Maybe #893 is related? |
Can you specify what keyword arguments are most important to set for those recipes? |
https://github.com/SciML/SciMLBase.jl/blob/master/src/solutions/solution_interface.jl#L151-L164
|
I would also need custom keywords for JuliaDynamics packages, so I'm subscribing to this issue! |
Would love to see the Makie support for DifferentialEquations |
I have no idea what those should do as keyword arguments :D Are those referring to plot types? So |
Of course you (Makie) don't, because Makie doesn't supply their interpretation, the type-recipe does. I want my type recipe to add new keyword arguments to the pipeline, since the Makie keyword arguments are insufficient to describe things like "how many points to interpolate the continuous function by", nor should it try to do all of them. At some point, types need the ability to define new arguments.
This is still a major misunderstanding, since you're still thinking about keyword arguments Makie has, not the ones I need to add.
What's the proper way to do this?
The DiffEq example is a good one that is in wide use and has a few necessary kwargs. |
So as I said, getting kw arguments into a recipe isn't the problem, doing something with them is..
So I see mainly things like xlims, ylims, xguide, yguide etc being set in that recipe... Aren't those for the axis? |
Yes, but that's a red harring and completely unrelated to the issue. The issue is what to do with the |
That's all the ammo we need, thanks! @YingboMa is that enough to finish your prototype example from yesterday? using Makie
struct Solution{T,U}
ts::T
us::U
end
@recipe(SolutionPlot) do scene
Theme(
ccc = :red,
shift = 0
)
end
function Makie.plot!(sp::SolutionPlot{<:Tuple{<:Solution}})
sol = sp[1]
ts, us = sol[].ts, sol[].us
lines!(sp, ts, us .+ sp.shift[], color=sp.ccc[])
sp
end
sol = Solution(1:10, rand(10))
solutionplot(sol; shift=100, ccc=:darkblue) Also, does a recipe like this automatically compose with other recipes? |
But this kind of approach seems far from optimal though, and unlikely to stay as a stable interface. Why is it that function Makie.plot!(plot::Makie.Plot(AbstractTimeseriesSolution); vars = (1, 2, 3)) is initself not possible? |
You can do function plot!(plot::SomePlot{MyType})
haskey(plot, :var) || (plot.attributes[:var] = Node(default)
...
end to add it for a specific plot data type without adjusting the general default Attributes I suppose. |
Plot implements the dict interface, so this would be preferrable: function Makie.plot!(plot::Makie.Plot(AbstractTimeseriesSolution))
# plot contains any keyword arguments that you pass to plot(series; kw...)
var = get(plot, :var, Node(5))
density!(plot, @lift $var .* $(plot[1]).results)
end |
Oookay, this _partly) solves the issue. The default keywords still remains unfortunately. And sometimes the defaults depend on the input data. |
Ok, there was another bug for composing type recipes :D With those fixes this works: using GLMakie
struct AbstractTimeseriesSolution
results::Vector{Float32}
end
function Makie.plot!(plot::Makie.Plot(AbstractTimeseriesSolution))
# plot contains any keyword arguments that you pass to plot(series; kw...)
var = get(plot, :var, Node(5))
density!(plot, @lift $var .* $(plot[1]).results)
end
struct Test2
series
end
function Makie.plot!(plot::Makie.Plot(Test2))
arg1 = plot[1]
scatter!(plot, arg1[].series)
ser = AbstractTimeseriesSolution(arg1[].series)
plot!(plot,ser, var=10)
end
plot(Test2(rand(Float32, 10))) |
BTW, in the above |
I think it would still be nice to be able to access keyword arguments in function AbstractPlotting.convert_arguments(
::Type{<:Reliability},
probabilities::AbstractVector{<:Real},
frequencies::AbstractVector{<:Real},
)
return (map(Point2f0, probabilities, frequencies),)
end
function AbstractPlotting.convert_arguments(
::Type{P},
probabilities::AbstractVector{<:Real},
outcomes::AbstractVector{Bool},
algorithm,
) where {P<:Reliability}
meanprobabilities, meanfrequencies, _ = reliability_summary(
probabilities, outcomes, algorithm
)
return AbstractPlotting.convert_arguments(P, meanprobabilities, meanfrequencies)
end Users should be able to provide pre-binned Now I am in the process of adding another functionality (so-called consistency bars) which are computed by a resampling procedure that the user should be able to adjust. To limit the number of arguments my approach so far has been to use a custom In my opinion, this seems a bit weird since I would expect |
So, you can actually access kw-args in convert_arguments, but it hasn't really been advertised that much, because I'm not sure if I like how all of this works :D struct Solution
data
end
Makie.used_attributes(::Any, x::Solution) = (:attribute,)
# Convert for all point based types (lines, scatter)
function Makie.convert_arguments(p::Makie.PointBased, x::Solution; attribute = 1.0)
return convert_arguments(p, x.data .* attribute,)
end
scatter(Solution(rand(4)), attribute=10) We're a bit greedy with not passing all attributes to |
Ah nice, I didn't know BTW is the first argument the plot type? |
Yes ;) |
Thanks 👍 And I guess Makie specializes on the arguments to avoid unnecessary recomputations? E.g., if in my example above I define function Makie.used_attributes(::Reliability, ::AbstractVector{<:Real}, ::AbstractVector{<:Bool})
return (:binning, :bars)
end I would be able to use these keyword arguments in |
For the DiffEq type recipes, we need to have custom keyword arguments from users and to set a few other plotting attributes (labels). Is that able to be done?
The text was updated successfully, but these errors were encountered: