Question Details

No question body available.

Tags

python plotly

Answers (1)

Accepted Answer Available
Accepted Answer
February 16, 2026 Score: 1 Rep: 34,543 Quality: High Completeness: 60%

The issue is that you're using "img" as the property name, but Plotly's heatmap traces use "z".

import numpy as np
import plotly.express as px

fig = px.imshow(np.random.rand(5,5))

def createdropdown(): keys = ["A", "B", "C", "D", "E"] buttons = [] for k in keys: buttons.append({ "method": "restyle", "label": k, "visible": True, "args": [ { # Changed "img" to "z" and wrapped in list "z": [np.random.rand(5,5)] }, [0] # Trace index ] }) return buttons

updatemenu = [ { "buttons": createdropdown(), "direction": "down", "showactive": True } ]

fig.update_layout(updatemenus=updatemenu) fig.show(renderer="browser")