Skip to content

Fix px marginal color with named continuous color scales - #5839

Open
anyingiit wants to merge 1 commit into
plotly:mainfrom
anyingiit:fix-px-marginal-named-colorscale-2059
Open

anyingiit wants to merge 1 commit into
plotly:mainfrom
anyingiit:fix-px-marginal-named-colorscale-2059

Conversation

@anyingiit

Copy link
Copy Markdown

Link to issue

Closes #2059

Description of change

With a continuous color, marginal traces are colored with args["color_continuous_scale"][0]. For a named scale like "Viridis" that is the first character ('V'), and for a list of [position, color] pairs it is the pair itself, so px.scatter(..., color=<numeric>, marginal_x="box", color_continuous_scale="Viridis") raises an invalid marker.color error. This PR normalizes the scale with ColorscaleValidator (as is already done for the coloraxis) before taking its first color.

Motivation / disclosure: I had some spare AI-assistant quota (Claude Code) and am using it to try to help projects with open issues. The change was prepared with Claude Code and verified as listed below. If it doesn't fit, or you'd simply rather not take it, please feel free to close it, no hard feelings at all 🙂

Demo

import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="sepal_length",
                 marginal_x="box", color_continuous_scale="Viridis")
fig.data[1].marker.color  # before: ValueError (received 'V'); after: '#440154'

Testing strategy

Added test_marginal_color_with_continuous_color_scale in tests/test_optional/test_px/test_marginals.py (named, lowercase, reversed _r, list of colors and list of pairs × histogram/box/violin/rug). 16 of its 20 cases fail on main (the list-of-colors cases already worked) and all pass with this change.

  • python -m pytest tests/test_optional/test_px --ignore=.../test_imshow.py --ignore=.../test_trendline.py: 1083 passed, 3 failed (test_render_mode, which needs statsmodels, not installed locally)
  • ruff format --check . and ruff check on the changed files: clean

Guidelines

When color is continuous, Plotly Express colors marginal traces with the
first entry of color_continuous_scale. For a named scale such as
"Viridis" that entry was the first character of the string ("V"), and
for a list of [position, color] pairs it was the pair itself, both of
which are invalid marker colors. Normalize the scale with
ColorscaleValidator before taking its first color.

Closes plotly#2059
@anyingiit
anyingiit force-pushed the fix-px-marginal-named-colorscale-2059 branch from 572dd47 to bb9ca36 Compare October 22, 2026 19:23

This branch has not been deployed

No deployments
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.

Error in plotly express scatter with continuous_color_scale and marginal_x

1 participant