Closed
Description
Before complaining about something not working properly, I have to say, Plotly rocks! You guys are doing fantastic work - keep it up!!
That said, when I have empty string values in a categorical column and use that column as the color
argument in Plotly Express, the category is automatically hidden from the legend but appears on the graph.
Running this code with Plotly.py 4.14.3 will reproduce the behavior:
import plotly.express as px
import plotly.offline as py
df = px.data.gapminder().query("continent=='Oceania'")
df.country = df.country.replace('Australia', '')
fig = px.bar(df, x="year", y="lifeExp", color='country')
py.plot(fig) # Only New Zealand will show in the legend
This line is what causes this behavior. I am sure there is a reasonable thought process behind this, but for me, this behavior was unexpected and confusing.
I would propose one or some combination of the following:
- Make it clear in the docs that this is the behavior (perhaps it's already there and I simply missed it)
- Raise a warning that this is the default behavior when a blank category value is detected
- Provide an option to enable/disable this behavior in the call to the plotly.express plotting function (e.g.
px.line(df, 'x', 'y', color='z', hide_blank_categories = False)
- Make the default behavior to show all traces in the legend, even if the category is blank (though this might be unexpected and confusing when a user sees a legend entry with no name)
I'm open to any other suggested resolutions from the Plotly team, but I would love this to be "fixed".
Thanks!!!
Metadata
Metadata
Assignees
Labels
No labels