-
-
Notifications
You must be signed in to change notification settings - Fork 328
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
Add ECDF plot #1310
Add ECDF plot #1310
Conversation
Looks very good to me, thanks for the contribution! Any thoughts @piever or @SimonDanisch? |
Looks good to me to, thanks for the nice contribution! I've left a very minor comment. |
Not a very constructive comment, but I am quite convinced that the right way to set this up would be a plot recipe for something a Stats package returns and not a function that receives the raw data, then calls the stats package function on it and then finally plots it. |
The current convention for distributions/samples is to have both. For example, there's But there might be a way to delete some code here to make the plotting of |
I also think so, I have added some suggestions on how to unify the implementation (it basically does everything via |
@piever for some reason with the recommended changes I get the error: ERROR: PlotMethodError: no ecdfplot method for arguments (::Vector{Point{2, Float32}}). To support these arguments, define
plot!(::Combined{Makie.ecdfplot, S} where S<:Tuple{Vector{Point{2, Float32}}}) |
Mhm, I confess I'm a bit rusty on the details on how this works. Does the method below get called? function convert_arguments(::Type{<:ECDFPlot}, x::AbstractVector; npoints=10_000, weights=StatsBase.Weights(Float64[]))
ecdf = StatsBase.ecdf(x; weights=weights)
return convert_arguments(Stairs, ecdf, npoints=npoints)
end In that case, I thought that would call the EDIT: I've tested locally and indeed |
Can you give me a quick MWE, so I can try it out and see what's going on? |
So, MWE would be as follows: julia> using Makie
julia> @recipe(MyPlot) do scene
Theme(;
default_theme(scene, Scatter)...
)
end
julia> Makie.convert_arguments(::Type{<:MyPlot}, x) = PlotSpec{Scatter}(convert_arguments(Scatter, x)...)
julia> myplot(1:3)
ERROR: PlotMethodError: no myplot method for arguments (::Vector{Point{2, Float32}}). To support these arguments, define
plot!(::Combined{myplot, S} where S<:Tuple{Vector{Point{2, Float32}}})
Available methods are:
Stacktrace:
[1] _plot!(p::Combined{myplot, Tuple{Vector{Point{2, Float32}}}})
@ Makie C:\Users\pietro\.julia\packages\Makie\PFSZS\src\interfaces.jl:347
[2] plot!(p::Combined{myplot, Tuple{Vector{Point{2, Float32}}}})
@ Makie C:\Users\pietro\.julia\packages\Makie\PFSZS\src\interfaces.jl:342
[3] plot!(scene::Scene, P::Type{Combined{myplot, Tuple{UnitRange{Int64}}}}, attributes::Attributes, input::Tuple{Observable{UnitRange{Int64}}}, args::Observable{Tuple{Vector{Point{2, Float32}}}})
@ Makie C:\Users\pietro\.julia\packages\Makie\PFSZS\src\interfaces.jl:428
[4] plot!(scene::Scene, P::Type{Combined{myplot, ArgType} where ArgType}, attributes::Attributes, args::UnitRange{Int64}; kw_attributes::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:show_axis,), Tuple{Bool}}})
@ Makie C:\Users\pietro\.julia\packages\Makie\PFSZS\src\interfaces.jl:339
[5] plot(P::Type{Combined{myplot, ArgType} where ArgType}, args::UnitRange{Int64}; axis::NamedTuple{(), Tuple{}}, figure::NamedTuple{(), Tuple{}}, kw_attributes::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Makie C:\Users\pietro\.julia\packages\Makie\PFSZS\src\figureplotting.jl:28
[6] plot
@ C:\Users\pietro\.julia\packages\Makie\PFSZS\src\figureplotting.jl:18 [inlined]
[7] myplot(args::UnitRange{Int64}; attributes::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Main C:\Users\pietro\.julia\packages\MakieCore\S8PkO\src\recipes.jl:31
[8] myplot(args::UnitRange{Int64})
@ Main C:\Users\pietro\.julia\packages\MakieCore\S8PkO\src\recipes.jl:31
[9] top-level scope
@ REPL[10]:1 IMO, once |
Hm weird, It seems the |
changing that to not applying |
Do you want to make that change in this PR, and see if it passes tests? function apply_convert!(P, attributes::Attributes, x::PlotSpec{S}) where S
args, kwargs = x.args, x.kwargs
# Note that kw_args in the plot spec that are not part of the target plot type
# will end in the "global plot" kw_args (rest)
for (k, v) in pairs(kwargs)
attributes[k] = v
end
return (S, args) # this change, line 153 in interfaces.jl
end |
Everything seems to work, save for one method, and it's not clear to me why: julia> using GLMakie, StatsBase
julia> x = randn(200);
julia> w = weights(rand(200));
julia> plot(ecdf(x; weights=w)) # this is fine
julia> ecdfplot(x) # also fine
julia> ecdfplot(x; weights=w)
Error showing value of type Makie.FigureAxisPlot:
ERROR: MethodError: no method matching gl_convert(::Weights{Float64, Float64, Vector{Float64}})
Closest candidates are:
gl_convert(::GLMakie.GLAbstraction.AbstractLazyShader, ::Any) at /Users/sethaxen/projects/Makie.jl/GLMakie/src/GLAbstraction/GLShader.jl:203
gl_convert(::Function, ::Any) at /Users/sethaxen/projects/Makie.jl/GLMakie/src/GLAbstraction/GLUniforms.jl:266
gl_convert(::StaticArrays.SMatrix{N, M, T, L} where L) where {N, M, T} at /Users/sethaxen/projects/Makie.jl/GLMakie/src/GLAbstraction/GLUniforms.jl:230
... |
It seems like an another bug that the keyword argument gets passed to the backend even if it is in |
Co-authored-by: Pietro Vertechi <pietro.vertechi@protonmail.com>
No, making it part of the theme doesn't change anything, with or without the |
Turns out those |
That fixed it for me! This should be ready for final review then. |
LGTM! |
This PR adds
ecdfplot
for plotting empirical cumulative distribution functionsStatsBase.ECDF
objectsI'm not sure how/if to document the conversion functions.
Example usage: