-
Notifications
You must be signed in to change notification settings - Fork 35
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
Integration with Plots.jl #256
Comments
You mean that the fact that values no longer inherit from |
Yes - it is going to break (actually I think not break but produce deprecation warnings) a lot of code that used to work when plotting data frames with categorical columns that are strings. But I guess you are right that CategoricalArrays.jl as a dependency for Plots.jl is problematic. However, maybe I was not right and it is not a problem. @daschw - do you have any opinion on this? |
I don't think it should print deprecation warnings, as AFAICT Plots.jl doesn't use |
Yes it relies on
and if
you get like 10 warnings now as:
is this clear now where the problem is? (still maybe nothing needs to be done if |
Thanks a lot for thinking of Plots and informing me! I don't have time right now, but I will check and report back (or ask some stupid questions) soon. |
So, from what I've tried now with CategoricalArrays master, it won't just work with @recipe f(::Type{T}, ::T) where {T <: CategoricalValue} = (get, string) It returns two functions. The first tells Plots how to convert CategoricalValues to something it can handle (String, Number) and the second defines how to format this converted values in the axes tick labels. I tested the recipe above and it works for both
Of course our preferred option would be the latter. We are currently working on supporting RecipesBase also with Makie. This will probably take a little longer, but when we have that you'd also have automatic Makie support for CategoricalArrays, if you include the recipe here. |
Ah that's too bad. I guess we'll have to depend on RecipesBase then (we already depend on JSON for similar reasons, which is absurd). We really need a mechanism for optional dependencies. Something I don't really understand: why doesn't Plots simply call |
This is what also assumed |
Consider plot(string.(cvs), 1:3) |
This I understand, but I guess recipes could allow to opt-out from a default behaviour which would be to convert to string (as currently I understand it errors). |
Yeah, maybe it would make sense to have string conversion as default. Honestly, I have never thought about this. Then it would error if no string method is defined for the type or lead to unexpected results like in my example above. Still, I guess you would not want that behavior for |
I think CategoricalArrays.jl is not a good dependency for Plots.jl as of today. The reason is that CategoricalArrays.jl invalidates a lot of compiled code from Base currently:
vs
so reduction of time-to-first-plot would be more problematic again. |
OK, thanks, good to know! |
Actually, the recipe would probably have to be: @recipe f(::Type{T}, ::T) where {T <: CategoricalValue} = (string, string) to ensure that numbers wrapped in categorical values are not treated as numeric. (In practice, |
Doesn't that break ordinal? That's a fairly common use case, using categorical values to order categories (e.g. groups) |
An excellent point - thank you for raising this. Is |
it could probably |
How about a new axis attribute |
and @recipe function f(::Type{T}, ::T) where {T <: CategoricalValue}
sortstrings --> true
string, string
end |
I'm not sure how I have no idea how Plots works, but ideally it could just treat |
Now I have checked that even now we do not handle order in from CategoricalArrays.jl correctly. When you run the following code:
while if you use the correct order by:
(of course this time strings are lost and numbers on X axis are printed) In short Plots.jl currently does not handle this correctly anyway, so:
|
This is what I have assumed that Plots.jl works like initially, but it seems Plots.jl takes a different approach (I am not sure why as I do not know the details of Plots.jl either). |
That's also what I thought... |
I guess we can add a "try to convert to string" fallback for |
Hi - where things at with this issue? I'm trying to make a plot where the x-axis is a categorical array with custom sorting of the levels. If I just try to plot it outright, I get the error |
Apparently I asked a similar question about 2.5 years ago ... https://discourse.julialang.org/t/ordering-the-y-axis-values-in-a-dotplot/10642 . It has a work-around. But would be nice if Categorical arrays just worked. |
Do we have a solution yet on ordering the x axis ticks for violin like categorical plots ?
I get
|
OK, we can't leave this without a solution. See #340. |
I am making an issue here, because what I discuss is not released yet.
When we deprecate
CategoricalString
we should coordinate with Plots.jl so that it is aware ofCategoricalValue{String}
and properly unwrap it (or maybe even properly unwrap anyCategoricalValue
), as otherwise a lot of plotting code that was working in the past will be broken.The text was updated successfully, but these errors were encountered: