-
-
Notifications
You must be signed in to change notification settings - Fork 317
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 custom colorization to boxplot #1032
Conversation
Thank you :) I'll leave the review to @piever if possible... Warning: failed to run `@example` block in src/plotting_functions/boxplot.md:9-18
│ ```@example
│ using CairoMakie
│ CairoMakie.activate!() # hide
│ Makie.inline!(true) # hide
│
│ xs = rand(1:3, 1000)
│ ys = randn(1000)
│
│ boxplot(xs, ys)
│ ```
│ c.value =
│ MethodError: no method matching iterate(::RGBA{Float32})
│ Closest candidates are:
│ iterate(::Union{LinRange, StepRangeLen}) at range.jl:664
│ iterate(::Union{LinRange, StepRangeLen}, ::Int64) at range.jl:664
│ iterate(::T) where T<:Union{Base.KeySet{var"#s79", var"#s78"} where {var"#s79", var"#s78"<:Dict}, Base.ValueIterator{var"#s77"} where var"#s77"<:Dict} at dict.jl:693
│ ...
└ @ Documenter.Expanders ~/.julia/packages/Documenter/xb5lD/src/Expanders.jl:563
┌ Warning: failed to run `@example` block in src/plotting_functions/boxplot.md:20-30
│ ```@example
│ using CairoMakie
│ CairoMakie.activate!() # hide
│ Makie.inline!(true) # hide
│
│ xs = rand(1:3, 1000)
│ ys = randn(1000)
│ dodge = rand(1:2, 1000)
│
│ boxplot(xs, ys, dodge = dodge, show_notch = true)
│ ```
│ c.value =
│ MethodError: no method matching iterate(::RGBA{Float32})
│ Closest candidates are:
│ iterate(::Union{LinRange, StepRangeLen}) at range.jl:664
│ iterate(::Union{LinRange, StepRangeLen}, ::Int64) at range.jl:664
│ iterate(::T) where T<:Union{Base.KeySet{var"#s79", var"#s78"} where {var"#s79", var"#s78"<:Dict}, Base.ValueIterator{var"#s77"} where var"#s77"<:Dict} at dict.jl:693
│ ...
└ @ Documenter.Expanders ~/.julia/packages/Documenter/xb5lD/src/Expanders.jl:563
[ Info: CrossReferences: building cross-references.
[ Info: CheckDocument: running document checks.
[ Info: Populate: populating indices.
ERROR: LoadError: `makedocs` encountered an error. Terminating build |
Yes I forgot to take into account the case where the provided |
Thanks for the PR! I've added a comment with a suggestion to make the code simpler / easier to reason about. |
Ready to merge i think |
This probably needs an example in the docs (to be added here). You can probably take one of the examples from About the interface, I think it'd be good to be consistent with It should be pretty easy to get a consistent interface by reusing the code in the violin recipe. In particular, you'll probably need There is only a minor twist compared to |
Sorry I'm stuck and I'm spending way too much time on this. Please see in the latest commit how I'm trying to do your approach. I get this error because I can't find a way to store the colors in a convertible type. Can you help me with this stacktrace ?
I also think the API is getting weird this way because we use
Boxplot is a composition of two plots and it makes sense that attributes lengths are different for both. I know this has been discussed at length for violins, but I kind of think the same logic should apply. It would also make as much sense for boxplot's api to be consistent with crossbar (which works with box length and not data length). |
Okay I just needed a tea break. Now it's working, here are the possible calls:
scalar outliercolor:
scalar color :
both scalar :
scalar color and custom outliercolors
I think this covers all cases. I still think the logic of the API should be length of boxes but I understand that consistency is key. I guess this is a discussion for another PR, maybe for 1.0. In the meantime, this API allows any level of customization. |
Co-authored-by: Pietro Vertechi <[email protected]>
Co-authored-by: Pietro Vertechi <[email protected]>
Do I need to do something to merge to master ? |
Thank you for this PR and your perseverance to push it to the finish line! :) |
No problem, thank you for the feedback and for maintaining this nice package :) |
Hello,
I have noticed a missing feature in Makies boxplots which is that you cannot make boxplots with different colors, which is a very common use of boxplots to show multiple experiments separated by a dodge. After looking into the code, I understood that this is because the way it handles the color of the outliers. Specifically, the length of the
color
attribute had to match the number of boxes (if not a scalar) but theoutliercolor
attribute was passed toscatter!
, which means that its length has to match the number of outliers. Currently, when the outliercolor attribute is left to automatic, specifying boxes colors fails:Or with symbol colors:
That is because a scalar
color
is assumed when determining theoutliercolor
automatically. A partial workaround was thus to pass a custom value:But maybe we want the outlier colors to match that of the boxes. It is currently impossible to do this.
This PR fixes this. Now the automatic behavior is to color the outliers w.r.t. their boxes:
This works also horizontally:
One can still pass a custom scalar color for the boxes:
makes 6 red boxplots with red outliers
Or a mapping for the boxes and a scalar for the outliers:
makes 6 purple and yellow boxes with red outliers
Or a custom mapping for the outliers, different from the boxes:
If these changes are accepted, I will also make some changes to the documentation to explain how this works.
I'm also open to adding some other features if you think this is incomplete.
Best