plotly / plotly_express

Plotly Express - Simple syntax for complex charts. Now integrated into plotly.py!
https://plot.ly/python/plotly-express/
MIT License
4 stars 0 forks source link

Infer categorical order from ordered pandas categoricals #158

Open joelostblom opened 4 years ago

joelostblom commented 4 years ago

It would be nice if px could infer the order of categorical columns if they are already set in pandas.

species_cat = pd.CategoricalDtype(categories=['virginica', 'versicolor', 'setosa'], ordered=True)
iris['species2'] = iris['species'].astype(species_cat)
px.histogram(iris, 'species2')

image

One approach to solve this might be to check the column data types for all columns mapped to a visual element and if they are ordered pandas categoricals, set the plot order via category_orders to be df['col'].cat.categories. So, essentially automating the below:

px.histogram(iris, 'species2', category_orders={'species2': iris['species2'].cat.categories})

image

I am not sure if there would be any cases when it would be disadvantageous to use the pandas order. At least for x, y, color, and facets I think it makes sense, thoughts?

bdwolfe commented 1 year ago

Yes, this would be very useful