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

[Bug] Plotly expresscolor_continuous_scale ignored when template hasautocolorscale=True #5433

Open
@antonymilne

Description

@antonymilne

Problem

When a Plotly template setscoloraxis_autocolorscale=True, thecolor_continuous_scale argument passed to plotly.express functions is ignored.

Reproduction

importplotly.expressaspximportplotly.graph_objectsasgodf=px.data.gapminder().query("year == 2007")template=go.layout.Template(layout=go.Layout(coloraxis_autocolorscale=True))# User specifies colorscale - THIS IS IGNOREDfig=px.choropleth(df,locations="iso_alpha",color="lifeExp",color_continuous_scale=["red","yellow","green"],template=template,)fig.show()# Renders with auto-detected scale, not red-yellow-green

Root cause

As per theplotly docs, whenautocolorscale=True, the colorscale is auto-detected based on the data, ignoring any explicitcolorscale setting (this itself is quite confusing behaviour I think, but that's a separate issue - let's assume for now it should be left with that logic):

In casecolorscale is unspecifiedorautocolorscale is True, the default palette will be chosen according to whether numbers in thecolor array are all positive, all negative or mixed.

In the following codeautocolorscale is not set oncoloraxis1. This means the template'sautocolorscale=True is inherited, causing the user'scolor_continuous_scale to be completely ignored:

layout_patch["coloraxis1"]=dict(
colorscale=colorscale_validator.validate_coerce(
args["color_continuous_scale"]
),
cmid=args["color_continuous_midpoint"],
cmin=range_color[0],
cmax=range_color[1],
colorbar=dict(
title_text=get_decorated_label(args,args[colorvar],colorvar)
),

Proposed fix

Whencolor_continuous_scale is explicitly provided, setautocolorscale=False oncoloraxis1 to ensure the user's colorscale is respected. I can raise a PR for this if you like!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp