Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix: Respect user-specified color_continuous_scale when template has …
…autocolorscale=True

When a user explicitly provides color_continuous_scale, it should always be
respected, even if the template has coloraxis_autocolorscale=True. Previously,
the template's autocolorscale setting would override the user's explicit
colorscale.

The fix tracks whether color_continuous_scale was explicitly provided by the
user (before apply_default_cascade fills it from template/defaults), and only
sets autocolorscale=False when the user explicitly provided a colorscale. This
preserves automatic diverging palette selection when colorscale comes from
template/defaults.

Changes:
- plotly/express/_core.py: Track user_provided_colorscale and conditionally
  set autocolorscale=False only when user explicitly provides colorscale
- plotly/express/_imshow.py: Same fix for imshow() function
  • Loading branch information
antonymilne committed Dec 2, 2025
commit 1b1fa930296bfef48f6c53fe4e4a9c7ac19c4b33
13 changes: 12 additions & 1 deletion plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,12 @@ def get_groups_and_orders(args, grouper):
def make_figure(args, constructor, trace_patch=None, layout_patch=None):
trace_patch = trace_patch or {}
layout_patch = layout_patch or {}
# Track if color_continuous_scale was explicitly provided by user
# (before apply_default_cascade fills it from template/defaults)
user_provided_colorscale = (
"color_continuous_scale" in args
and args["color_continuous_scale"] is not None
)
apply_default_cascade(args)

args = build_dataframe(args, constructor)
Expand Down Expand Up @@ -2704,7 +2710,7 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
range_color = args["range_color"] or [None, None]

colorscale_validator = ColorscaleValidator("colorscale", "make_figure")
layout_patch["coloraxis1"] = dict(
coloraxis_dict = dict(
colorscale=colorscale_validator.validate_coerce(
args["color_continuous_scale"]
),
Expand All @@ -2715,6 +2721,11 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
title_text=get_decorated_label(args, args[colorvar], colorvar)
),
)
# Set autocolorscale=False if user explicitly provided colorscale. Otherwise a template
# that sets autocolorscale=True would override the user provided colorscale.
if user_provided_colorscale:
coloraxis_dict["autocolorscale"] = False
layout_patch["coloraxis1"] = coloraxis_dict
for v in ["height", "width"]:
if args[v]:
layout_patch[v] = args[v]
Expand Down
13 changes: 12 additions & 1 deletion plotly/express/_imshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ def imshow(
axes labels and ticks.
"""
args = locals()
# Track if color_continuous_scale was explicitly provided by user
# (before apply_default_cascade fills it from template/defaults)
user_provided_colorscale = (
"color_continuous_scale" in args
and args["color_continuous_scale"] is not None
)
apply_default_cascade(args)
labels = labels.copy()
nslices_facet = 1
Expand Down Expand Up @@ -419,14 +425,19 @@ def imshow(
layout["xaxis"] = dict(scaleanchor="y", constrain="domain")
layout["yaxis"]["constrain"] = "domain"
colorscale_validator = ColorscaleValidator("colorscale", "imshow")
layout["coloraxis1"] = dict(
coloraxis_dict = dict(
colorscale=colorscale_validator.validate_coerce(
args["color_continuous_scale"]
),
cmid=color_continuous_midpoint,
cmin=zmin,
cmax=zmax,
)
# Set autocolorscale=False if user explicitly provided colorscale. Otherwise a template
# that sets autocolorscale=True would override the user provided colorscale.
if user_provided_colorscale:
coloraxis_dict["autocolorscale"] = False
layout["coloraxis1"] = coloraxis_dict
if labels["color"]:
layout["coloraxis1"]["colorbar"] = dict(title_text=labels["color"])

Expand Down