-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Using custom buttons to change the colorscale of a mesh trace does not behave as expected.
First, if I try to use a custom button to restyle the colorscale of a mesh using a scale existing in the python api but (I assume) not in the Javascript library, it will use some default colorscale instead.
Show code
import plotly
data = dict(
type='mesh3d',
x=[0, 1, 2, 0],
y=[0, 0, 1, 2],
z=[0, 2, 0, 1],
i=[0, 0, 0, 1],
j=[1, 2, 3, 2],
k=[2, 3, 1, 3],
intensity=[-1, -0.5, 0.5, 1],
colorscale='Phase',
)
button_1 = dict(
method='restyle', label='Change colorscale',
args=['colorscale', 'Phase']
)
layout = {'updatemenus': [{
'type': 'buttons', 'buttons': [button_1],
}]}
plotly.graph_objects.Figure(data, layout).show('browser')
The second issue I found while trying to work around this is that in order to supply a custom colorscale I need to convert it to a string and replace all '
with "
. This does not seem reasonable to expect the users to do.
Show code
import plotly
my_scale = [
[0, 'rgb(0, 255, 0)'],
[1, 'rgb(255, 0, 0)'],
]
data = dict(
type='mesh3d',
x=[0, 1, 2, 0],
y=[0, 0, 1, 2],
z=[0, 2, 0, 1],
i=[0, 0, 0, 1],
j=[1, 2, 3, 2],
k=[2, 3, 1, 3],
intensity=[-1, -0.5, 0.5, 1],
colorscale=my_scale,
)
button_1 = dict(
method='restyle', label='As list',
args=['colorscale', my_scale]
)
button_2 = dict(
method='restyle', label='As string',
args=['colorscale', str(my_scale)]
)
button_3 = dict(
method='restyle', label='As string with double qutes',
args=['colorscale', str(my_scale).replace("'", '"')]
)
layout = {'updatemenus': [{
'type': 'buttons', 'buttons': [button_1, button_2, button_3],
}]}
plotly.graph_objects.Figure(data, layout).show('browser')
The ideal behavior would, imho, to be able to supply any of the colorscales available in the python api, but I can imagine that this would require quite elaborate solutions. At minimum there should be some mention of this limitation in the documentation.
As for the workaround with string quotes, I would like to see this fixed so that it is possible to just pass a list.