Skip to content

Missing colorscales in ui buttons #5189

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lucasimi opened this issue May 18, 2025 · 0 comments
Open

Missing colorscales in ui buttons #5189

lucasimi opened this issue May 18, 2025 · 0 comments

Comments

@lucasimi
Copy link

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).

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

No branches or pull requests

1 participant