Hello,
I want to create a dynamic chart with Plotly in Python -> change the style option via buttons in the graph itself. Therefore, plotly offers the buttons or drowdownmenus. My current problem now is, that I would like to hide some of these buttons depending on which one is active.
My example is a plot where I can change my graph from lines into markers (first button set) and as special option for the lines I offer dotted, dashed and solid line (second button set).
Obviously, offering the second button set when βMarkersβ is active doesnβt make sense. So I would like to hide the second set. But until now I didnβt find a solution.
I am using the offline version of plotly.
I would appreciate any suggestions, thank you.
My mini example:
import plotly as py
import plotly.graph_objs as go
x_ = [1, 2, 3, 4, 5, 6, 7, 8 , 9, 10]
y_ = [1, 1.2, 1.4, 1.5, 1.6, 1.5, 1.4, 1.4, 1.35, 1.3]
trace_ = go.Scatter(
x = x_,
y = y_,
mode = "lines",
line = dict(
dash = "dot"
)
)
layout_ = go.Layout(
autosize = True
)
updatemenus_ = list([
dict(
buttons = list([
dict(
args=['mode', 'lines'],
label='Lines',
method='restyle'
),
dict(
args=['mode', 'markers'],
label='Markers',
method='restyle'
)
]),
direction = 'left',
pad = {'r': 10, 't': 10},
showactive = True,
type = 'buttons',
x = 0.1,
xanchor = 'right',
y = 1.1,
yanchor = 'top'
),
dict(
buttons = list([
dict(
args=['line', {'dash': 'dot'}],
label='Dotted Line',
method='restyle'
),
dict(
args=['line', {'dash': 'dash'}],
label='Dashed Line',
method='restyle'
),
dict(
args=['line', {'dash': 'solid'}],
label='Solid Line',
method='restyle'
)
]),
direction = 'right',
pad = {'r': 10, 't': 10},
showactive = True,
type = 'buttons',
x = 0.5,
xanchor = 'right',
y = 1.1,
yanchor = 'top'
),
])
layout_['updatemenus'] = updatemenus_
fig = dict(data=[trace_], layout=layout_)
py.offline.plot(fig, filename='MiniExample.html')