plotly / plotly/plotly.py

Missing colorscales in ui buttons

Open
#5,189 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

In the following code I created a simple plot with a dropdown menu where each button is expected to modify the colorscale. However, some of these don't seem to work properly and when the corresponding button is clicked, a default colorscale is applied instead.


import plotly.graph_objects as go
import numpy as np

# Generate sample data
np.random.seed(42)
x = np.random.rand(100)
y = np.random.rand(100)
z = np.sqrt(x**2 + y**2)

# Available colormaps
colorscales = ['Viridis', 'Cividis', 'Plasma', 'Inferno', 'Magma']

# Create the initial figure with one colorscale
scatter = go.Scatter(
    x=x,
    y=y,
    mode='markers',
    marker=dict(
        size=10,
        color=z,
        colorscale=colorscales[0],
        colorbar=dict(title='Value'),
        showscale=True
    )
)

fig = go.Figure(data=[scatter])

# Add dropdown menu
fig.update_layout(
    updatemenus=[
        dict(
            buttons=[
                dict(
                    label=scale,
                    method='restyle',
                    args=[{'marker.colorscale': [scale]}]
                )
                for scale in colorscales
            ],
            direction='down',
            showactive=True,
            x=1.1,
            y=1
        )
    ],
    title="Scatter Plot with Colormap Dropdown",
    xaxis_title="X",
    yaxis_title="Y"
)

fig.show()

In this plot only 'Viridis' and 'Cividis' colorscales are supported. More in general it seems to me that the only supported ones are those defined in plotly.colors.plotlyjs (only the non-reversed ones).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Python reproduction and compare the dropdown behavior with the names available in plotly.colors.plotlyjs. Trace how the Plotly Python figure serializes colorscale values for the buttons; done means the listed colorscales are accepted and applied consistently when selected.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.