Skip to content

Conversation

@antonymilne
Copy link

@antonymilne antonymilne commented Dec 2, 2025

Fixes #5433. 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.

A couple of tests are failing but I'm pretty sure it's not my fault.

Here's the behaviour now. Before this PR, all plots in the above table would have looked the same with the exception of the top left one, where the user-specified color_continuous_scale would have been ignored.

autocolorscale=True autocolorscale=False
01_autocolorscale_True_colorscale_red_yellow_green 02_autocolorscale_False_colorscale_red_yellow_green
03_autocolorscale_True_no_colorscale_sequential 04_autocolorscale_False_no_colorscale_sequential
07_autocolorscale_True_no_colorscale_diverging 08_autocolorscale_False_no_colorscale_diverging

Code PR

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the code generator and not the generated files.
  • I have added tests or modified existing tests.
  • For a new feature, I have added documentation examples (please see the doc checklist as well).
  • I have added a CHANGELOG entry if changing anything substantial.
  • For a new feature or a change in behavior, I have updated the relevant docstrings in the code.

…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
Add tests to verify that user-provided color_continuous_scale overrides
template autocolorscale=True, and that template autocolorscale is respected
when user doesn't provide a colorscale.

Changes:
- tests/test_optional/test_px/test_colors.py: Add test_color_continuous_scale_autocolorscale()
- tests/test_optional/test_px/test_imshow.py: Add test_imshow_color_continuous_scale_autocolorscale()
@antonymilne antonymilne marked this pull request as ready for review December 2, 2025 11:51
@antonymilne antonymilne changed the title Fix: Respect user-specified color_continuous_scale when template has … [Fix] Always respect user-specified color_continuous_scale Dec 2, 2025
Add changelog entry for PR plotly#5439 fixing issue where user-specified
color_continuous_scale was ignored when template had autocolorscale=True.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Plotly express color_continuous_scale ignored when template has autocolorscale=True

1 participant