-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
Better integration with CategoricalArrays.jl in keyword attributes #2173
Comments
I think Plots mostly should support CategoricalArrays out of the box, no? Can you give an example where Plots does not have the desired behaviour? |
Hi @mkborregaard , I am trying to find some time to reproduce the issue I had last week. Got busy with some other projects, but I should return soon. Sorry for the delay. |
Finally found the time to come back to this. The following code reproduces the issue: using Plots
using CategoricalArrays
x = rand(100)
y = rand(100)
c = rand(Int, 100)
scatter(x, y, zcolor=c) # works fine
scatter(x, y, zcolor=categorical(c)) # throws error Could you please advise on how to fix it? I am doing a presentation tomorrow, and will have to hack my plot recipes temporarily to convert the categorical values to integers. |
ah, I see. Categorical for attributes, not data. |
Maybe separate the two cases as suggested. When the categorical value is ordered, just plot the color using My real issue is that I want to color points properly no matter the type of the variables. For example, I have a point set in 2D plane where colors can be continuous variables, categorical variables, etc. Is there a keyword in Plots.jl that represents this general coloring goal? |
Let's say we are looking at the traditional data types in statistics:
Do we have a good mechanism to write recipes that accept arrays of any type, figures out the corresponding scitype of the entries with "ScientificTypes.jl" and then maps the correct keyword (e.g. |
Not really but I can see how that would be useful. The design predates CategoricalArrays |
Thank you @mkborregaard what can be done meanwhile? I was using |
Below is a snippet of code that converts a categorical array into an integer coding for plotting: using CategoricalArrays
a = categorical(["AB", "CD"])
b = CategoricalArrays.order(a.pool)[a.refs]
2-element Array{UInt32,1}:
0x00000001
0x00000002 So Plots.jl could handle this conversion internally in its plot recipes. Another issue that I can't figure out how to solve is the existence of missing values: a = categorical(["AB", missing, "CD"]) In this case the snippet of code above does not work. Where I can add that first code snippet in Plots.jl so that it handles categorical arrays without crashing? Ideally the plot recipe would change completely, but that is not urgent. cc: @mlubin |
This is an issue that could be discussed in detail in vizcon for the new recipe system instead. Recipes and plots that consider scientific types besides just raw types. |
It seems like the basic series types doesn't support categorical values. Categorical values are relevant in classification tasks with MLJ.jl for example.
One option is to add explicit support in Plots.jl to handle types from CategoricalArrays.jl Another option is to modify plot recipes in my own packages to handle categorical values: convert them manually to Integer types and then plot. Since I think this feature is useful to many more users in the ecosystem, I think the first option is the way to go.
Could you please clarify the current support of Plots.jl with CategoricalArrays.jl types? Can you please guide me where I could change the Plots.jl codebase to add support if the support is not there yet?
The text was updated successfully, but these errors were encountered: