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
Prev Previous commit
Next Next commit
Add tests for color_continuous_scale autocolorscale behavior
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()
  • Loading branch information
antonymilne committed Dec 2, 2025
commit cf3eb8e5b4ba61a71de8ce860fdd3757b11cbf81
3 changes: 1 addition & 2 deletions plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2489,8 +2489,7 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
# 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
"color_continuous_scale" in args and args["color_continuous_scale"] is not None
)
apply_default_cascade(args)

Expand Down
3 changes: 1 addition & 2 deletions plotly/express/_imshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ def imshow(
# 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
"color_continuous_scale" in args and args["color_continuous_scale"] is not None
)
apply_default_cascade(args)
labels = labels.copy()
Expand Down
21 changes: 21 additions & 0 deletions tests/test_optional/test_px/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,24 @@ def test_color_categorical_dtype():
px.scatter(
df[df.day != df.day.cat.categories[0]], x="total_bill", y="tip", color="day"
)


def test_color_continuous_scale_autocolorscale():
# User-provided colorscale should override template autocolorscale=True
fig = px.scatter(
x=[1, 2],
y=[1, 2],
color=[1, 2],
color_continuous_scale="Viridis",
template=dict(layout_coloraxis_autocolorscale=True),
)
assert fig.layout.coloraxis1.autocolorscale is False

# Without user-provided colorscale, template autocolorscale should be respected
fig2 = px.scatter(
x=[1, 2],
y=[1, 2],
color=[1, 2],
template=dict(layout_coloraxis_autocolorscale=True),
)
assert fig2.layout.coloraxis1.autocolorscale is None
17 changes: 17 additions & 0 deletions tests/test_optional/test_px/test_imshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ def test_colorscale():
assert fig.layout.coloraxis1.colorscale[0] == (0.0, "#440154")


def test_imshow_color_continuous_scale_autocolorscale():
# User-provided colorscale should override template autocolorscale=True
fig = px.imshow(
img_gray,
color_continuous_scale="Viridis",
template=dict(layout_coloraxis_autocolorscale=True),
)
assert fig.layout.coloraxis1.autocolorscale is False

# Without user-provided colorscale, template autocolorscale should be respected
fig2 = px.imshow(
img_gray,
template=dict(layout_coloraxis_autocolorscale=True),
)
assert fig2.layout.coloraxis1.autocolorscale is None


def test_wrong_dimensions():
imgs = [1, np.ones((5,) * 3), np.ones((5,) * 4)]
msg = "px.imshow only accepts 2D single-channel, RGB or RGBA images."
Expand Down