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

Override of color_discrete_sequence when using sequential integer color tags #134

Closed IlyaOrson closed 5 years ago

IlyaOrson commented 5 years ago

While using the scatter_3d functionality, I noticed that a discrete color requence gets overridden by the default continuous scale if the color keyword points to a column with sequential integer data instead of categorical data.

Here is a minimum working example of what I mean:

# maybe needed to reproduce from terminal
# import plotly.io as pio
# pio.renderers.default = "browser
import plotly.express as px
iris = px.data.iris()
# iris["species_id"] = [str(id) for id in iris["species_id"]]  # one workaround
fig = px.scatter_3d(
    iris,
    x='sepal_length',
    y='sepal_width',
    z='petal_width',
    color='species_id',  # works as intended with 'species' 
    color_discrete_sequence=px.colors.qualitative.Dark24,
    # color_continuous_scale=px.colors.qualitative.Dark24, # another workaround
)
fig.show()

Not sure if this is intended but it got me by surprise.

nicolaskruchten commented 5 years ago

Yes, this is intentional: px interprets numerical colors as sequential. The recommended way to accomplish what you're looking for would be to cast your numerical color column to a string column.

IlyaOrson commented 5 years ago

Got it, I'll close this then. Thanks!