You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Plotly express color_continuous_scale ignored when template has autocolorscale=True #5433
When a Plotly template sets coloraxis_autocolorscale=True, the color_continuous_scale argument passed to plotly.express functions is ignored.
Reproduction
importplotly.expressaspximportplotly.graph_objectsasgodf=px.data.gapminder().query("year == 2007")
template=go.layout.Template(layout=go.Layout(coloraxis_autocolorscale=True))
# User specifies colorscale - THIS IS IGNOREDfig=px.choropleth(
df,
locations="iso_alpha",
color="lifeExp",
color_continuous_scale=["red", "yellow", "green"],
template=template,
)
fig.show() # Renders with auto-detected scale, not red-yellow-green
Root cause
As per the plotly docs, when autocolorscale=True, the colorscale is auto-detected based on the data, ignoring any explicit colorscale setting (this itself is quite confusing behaviour I think, but that's a separate issue - let's assume for now it should be left with that logic):
In case colorscale is unspecified orautocolorscale is True, the default palette will be chosen according to whether numbers in the color array are all positive, all negative or mixed.
In the following code autocolorscale is not set on coloraxis1. This means the template's autocolorscale=True is inherited, causing the user's color_continuous_scale to be completely ignored:
When color_continuous_scale is explicitly provided, set autocolorscale=False on coloraxis1 to ensure the user's colorscale is respected. I can raise a PR for this if you like!
Agreed that this isn't the most intuitive behavior. We would be open to making this change if you could open a PR. The only notable concern would be around backwards compatibility if anyone was assuming this behavior.
In case colorscale is unspecified or autocolorscale is True, the default palette will be chosen according to whether numbers in the color array are all positive, all negative or mixed.
i.e. when autocolorscale=True and colorscale is specified explicitly, colorscale will be ignored. To me it really feels like the "or" condition here should be "and", so that autocolorscale is only relevant when colorscale isn't specified explicitly. I don't know whether this is a bug or intentional.
Either way, I decided that for simplicity I would just fix this on the Plotly Express side (where the bug is most obvious and problematic) to ensure there's no backwards compatibility issues.
Activity
robertclaus commentedon Nov 26, 2025
Agreed that this isn't the most intuitive behavior. We would be open to making this change if you could open a PR. The only notable concern would be around backwards compatibility if anyone was assuming this behavior.
antonymilne commentedon Dec 2, 2025
Hi @robertclaus, I've opened a PR to fix this in #5439.
I've gone for the "light touch" fix that only affects Plotly Express so there shouldn't be any concerns around backwards compatibility here.
Just to be clear, as I see it the underlying behaviour of plotly.js is quite confusing and unexpected:
i.e. when
autocolorscale=Trueandcolorscaleis specified explicitly,colorscalewill be ignored. To me it really feels like the "or" condition here should be "and", so thatautocolorscaleis only relevant whencolorscaleisn't specified explicitly. I don't know whether this is a bug or intentional.Either way, I decided that for simplicity I would just fix this on the Plotly Express side (where the bug is most obvious and problematic) to ensure there's no backwards compatibility issues.