【发布时间】:2022-11-14 05:29:44
【问题描述】:
我有一个情节,其中有 3 个子情节和一个下拉菜单。当我从下拉列表中选择一个时,我想更改 yaxis 子图文本。 yaxis.title or yaxis2.title 不工作。
注意:不使用破折号
如果我只能更改第 3 个子图 yaxis 标题文本(而不是第 1 个和第 2 个子图),有可能吗?
import plotly.graph_objs as go
from plotly import subplots
trace0 = go.Scatter(x=[1, 2, 3], y=[4, 5, 6], mode="lines+markers")
trace1 = go.Scatter(x=[1, 2, 3], y=[5, 4, 6], mode="lines+markers")
trace2 = go.Scatter(x=[1, 2, 3], y=[6, 5, 4], mode="lines+markers")
fig = subplots.make_subplots(rows=3,cols=1,shared_xaxes=True,horizontal_spacing=0.5)
fig.add_trace(trace0, 1, 1)
fig.add_trace(trace1, 1, 1)
fig.add_trace(trace2, 1, 1)
fig.add_trace(trace0, 2, 1)
fig.add_trace(trace0, 3, 1)
update_menus = [go.layout.Updatemenu(
active=0,
buttons=list(
[dict(label = 'All',
method = 'relayout',
args = [{'visible': [True, True, True,True,True]},
{'title': 'all',
'showlegend':True},
{'yaxis.title':'fgv','yaxis2.title':'ram','yaxis3.title':'gen'}]),
dict(label = 'First',
method = 'relayout',
args = [{'visible': [True, False, False,True,True]}, # the index of True aligns with the indices of plot traces
{'title': 'first',
'showlegend':True},
{'yaxis.title':'fgv','yaxis2.title':'ram','yaxis3.title':'gen'}]),
dict(label = 'Second',
method = 'relayout',
args = [{'visible': [False, True, False,True,True]},
{'title': 'second',
'showlegend':True},
{'yaxis.title':'fgv','yaxis2.title':'ram','yaxis3.title':'gen'}]),
dict(label = 'Third',
method = 'relayout',
args = [{'visible': [False, False, True, False,False]},
{'title': 'third',
'showlegend':True},
{'yaxis.title':'fgv','yaxis2.title':'ram','yaxis3.title':'gen'}]),
])
)
]
fig.show()
【问题讨论】:
-
我不明白如何通过下拉菜单更改第三个y轴的标题?
-
你的意思是下拉菜单包含不同的标签,用户会选择一个标签吗?
标签: plotly plotly-python