-
-
Notifications
You must be signed in to change notification settings - Fork 358
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
Convert series data to string as fallback. #2519
Conversation
Thank you for working on this. I think "not sorting categorical due to problems with handling multiple plots" makes sense (I understand the user can sort what is to be plotted before passing it for plotting - right?). |
Sorting is useful in two cases:
In other cases user sorting should solve it. |
OK, so apparently these convert to string fallbacks don't play well with animations. However, I was reading @bkamins comment JuliaData/CategoricalArrays.jl#256 (comment) on the order of categories again where he comes to the conclusion
This PR, if it passed tests, would be an implementation of the first bullet point without a recipe. We can also make it correct (second bullet) without integrating Plots and CategoricalArrays.jl. With #2503 and #2515 we can use the following type recipe: @recipe function f(::Type{T}, cv::T) where T <: CategoricalValue
level_strings = string.(levels(cv))
ticks --> eachindex(level_strings) # EDIT: `:=` would be safer than `-->`
cv -> levelcode(cv), i -> level_strings[Int(i)]
end For the example cstr = categorical(["B", "A", "C"])
cnum = categorical([10, 1, 2])
plot(cstr, cnum) |
you do not need integration I think - you can just |
That was actually still a quote from your post. However, I agree with your original opinion, because Plots does not want to sort |
Thanks for working on this! Unfortunately, the deprecation warnings are serious: these methods are going to be removed in the release after the next one (since BTW, have you tried with CategoricalArrays master? That's the version which is going to drop
Plots doesn't sort arrays, but doesn't it call |
It tells Plots: whenever you see an
Yes, everything I post here is with CategoricalArrays master.
julia> leves(["a", "b"])
ERROR: UndefVarError: leves not defined
Stacktrace:
[1] top-level scope at REPL[3]:1
[2] eval(::Module, ::Any) at ./boot.jl:331
[3] eval_user_input(::Any, ::REPL.REPLBackend) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
[4] run_backend(::REPL.REPLBackend) at /home/daniel/.julia/packages/Revise/Pcs5V/src/Revise.jl:1073
[5] top-level scope at none:0 How would it know, when to use I'm quite convinced that the recipe is the best option we have if we do not want Plots to depend on CategoricalArrays. |
The difference between
|
That's surprising. I asked because I see julia> lastindex(categorical(["a"])[1])
┌ Warning: `lastindex(x::CategoricalValue{String})` is deprecated, use `lastindex(String(x))` instead.
│ caller = top-level scope at REPL[6]:1
└ @ Core REPL[6]:1
1 |
OK, thanks for the hint! Let me check again. |
You were right, there are no warnings with this PR and CategoricalArrays#master. |
Do we have a solution yet on ordering the x axis ticks for violin like categorical plots ?
I get
|
With this we support the changes in CategoricalArrays.jl without introducing dependencies (JuliaData/CategoricalArrays.jl#256).
Before:
With this:
Note that the categories are not sorted. We did not have this before either. However, before the y axis would have been numeric, because we used to convert categorical arrays of numbers to numeric arrays. That is no longer possible without depending on CategoricalArrays, because a categorical array of numbers is not a subtype of
AbstractArray{<:Number}
anymore. @nalimilan pointed out in JuliaData/CategoricalArrays.jl#256 (comment) that the new behavior is actually correct.I played around with automatic sorting of categorical values along the axes with a new attribute
sortstrings
on a local branch and got it working, but only for single series. If a new series added a new categorical value to the axis, we would have to update all the axis positions of the previous series. This would mean a significant change in the recipe processing pipeline, which I do not want to do at this point. An alternative idea for the future could be do to a common final processing of all series ifsortstrings
is provided.I'm not sure, where in the pipeline these warnings above pop-up. We will have to investigate this further. Still I think this is an improvement to the current behavior of erroring, and we should probably release this soon.
cc: @mkborregaard @nalimilan @bkamins