plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
15.98k stars 2.53k forks source link

Problems with "Reds", "Turbo", "Inferno" (...?) colorscales #3860

Open filipesmg opened 2 years ago

filipesmg commented 2 years ago

There seems to be an issue with the "Reds" and "Turbo" colorscales. I couldn't find an existing issue about this, so here is how to reproduce: I just got this example from plotly page: https://plotly.com/python/dropdowns/#update-several-data-attributes And added the "Reds" and "Turbo" colorscales.

The "Reds" seem to work, but it is inverted when comparing to the "Blues" and "Greens": Screenshot 2022-08-20 at 16 25 34Screenshot 2022-08-20 at 16 31 13Screenshot 2022-08-20 at 16 25 45

The "Turbo", on the other hand, shows up like a "coolwarm" colorscale instead:

Screenshot 2022-08-20 at 16 25 58

These two are different than the ones described on the documentation here: https://plotly.com/python/builtin-colorscales/#builtin-sequential-color-scales

I had similar issues when using "Plotly.update" with plotly.js to update the coloscales.

edit: Also the "Inferno" shows as the "coolwarm" one:

Screenshot 2022-08-20 at 17 09 21

Probably there are others too.

AaronStiff commented 1 year ago

This seems to be an issue specific to that example, as just creating a trace with one of those colorscales works as intended."Blues" and "Greens" are actually the ones getting inverted.

AaronStiff commented 1 year ago

Smaller reproducible example:

import plotly.graph_objects as go

fig = go.Figure()
fig.add_trace(go.Heatmap(z=[[i for i in range(10)]], colorscale="Blues"))

fig.update_layout(
    updatemenus=[
        dict(
            buttons=list([
                dict(
                    args=["colorscale", "Blues"],
                    label="Blues",
                    method="restyle"
                ),
                dict(
                    args=["colorscale", "Reds"],
                    label="Reds",
                    method="restyle"
                )
            ]),
        ),
    ]
)

fig.show()

@alexcjohnson is this a plotly.js issue?

To start, the "Blues" colorscale is displayed correctly, as is the "Reds" if selected. But switching back from "Reds" to "Blues" somehow causes the colorscale to reverse.

Codepen if that's helpful: https://codepen.io/aaronstiff/pen/qBMzNjB

nicolaskruchten commented 1 year ago

I think the problem is that the args are interpreted 100% in Plotly.js which (awkwardly!) has its own definitions of colorscales, some of which share names with the Python ones (Reds, Blues) but maybe not orientations, and it's missing a whole bunch of the Python ones (Turbo, Inferno). If you try something like args=["colorscale", plotly.colors.sequential.Reds], I suspect you will get what you're looking for.

nicolaskruchten commented 1 year ago

So this isn't so much a Plotly.py or Plotly.js issue but an impedance mismatch between the two.

AaronStiff commented 1 year ago

Ah, I see.

However, giving colorscale the full reference to a colorscale results in similarly odd behaviour: switching to plotly.colors.sequential.Reds applies something that looks like RdBu, and switching back to plotly.colors.sequential.Blues does not change anything (still RdBu)