Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Fix] Support trace-specific color sequences in Plotly Express via templates#5437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
antonymilne wants to merge7 commits intoplotly:main
base:main
Choose a base branch
Loading
fromantonymilne:main

Conversation

@antonymilne
Copy link

@antonymilneantonymilne commentedNov 27, 2025
edited
Loading

Summary

Fixes#5416.

You can define color sequences in a template on a per-trace basis viatemplate.data.<trace_type>, but these were ignored by Plotly Express. Now they are used.

Changes

  • Modifiedapply_default_cascade() to check for trace-specific colors intemplate.data.<trace_type> before falling back totemplate.layout.colorway or default qualitative palette
  • Addedtest_px_templates_trace_specific_colors

Example Usage

See here for a demonstration of all (I think?) applicable trace types, i.e. those that supportmarker.color.

importplotly.expressaspximportplotly.graph_objectsasgotips=px.data.tips()# Create a custom template with trace-specific colorscustom_template=go.layout.Template(data={"histogram": [go.Histogram(marker=dict(color="orange")),go.Histogram(marker=dict(color="purple")),        ],"scatter": [go.Scatter(marker=dict(color="cyan")),go.Scatter(marker=dict(color="magenta")),        ],    },layout=go.Layout(colorway=["yellow","green"]),)template=pio.templates.merge_templates("plotly",custom_template)# Histogram uses histogram-specific colorsfig1=px.histogram(tips,x="total_bill",color="sex",template=template)# Scatter uses scatter-specific colorsfig2=px.scatter(tips,x="total_bill",y="tip",color="sex",template=template)# Box plot falls back to layout.colorwayfig3=px.box(tips,x="day",y="total_bill",color="sex",template=template)
changelog_histogramchangelog_scatterchangelog_box

Code PR

  • I have read through thecontributing notes and understand the structure of the package. In particular, if my PR modifies code ofplotly.graph_objects, my modifications concern the code generator andnot 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.

- Check template.data.<trace_type> for marker.color or line.color before falling back to template.layout.colorway- Handle timeline special case (maps to bar trace type)- Use marker colors first, fall back to line colors if no markers found- Fixes issueplotly#5416
- Modify apply_default_cascade to check template.data.<trace_type> for marker.color or line.color- Fallback to template.layout.colorway if trace-specific colors not found- Add comprehensive tests for trace-specific color sequences- Handle timeline special case (maps to bar trace type)- Follow existing patterns for symbol_sequence and line_dash_sequenceFixesplotly#5416
- Modify apply_default_cascade to read colors from template.data.<trace_type>- Prioritize trace-specific colors over layout.colorway- Add special case for timeline constructor (maps to bar trace type)- Add comprehensive tests for trace-specific color sequences- Test trace type isolation, fallback behavior, and timeline special case
@antonymilneantonymilne changed the titleTrace-specific colors[Fix] Support trace-specific color sequences in Plotly Express via templatesDec 1, 2025
@antonymilneantonymilne marked this pull request as ready for reviewDecember 1, 2025 12:00
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Feature request] Trace-specific color sequences in Plotly Express via templates

1 participant

@antonymilne

[8]ページ先頭

©2009-2025 Movatter.jp