我最近正在探索Plotly,我想知道是否存在一种共享绘图的方法,并允许查看者在对数轴和线性轴之间切换。
有什么建议吗?
答案 0 :(得分:1)
Plotly具有dropdown功能,该功能允许用户动态更新绘图样式和/或显示的迹线。以下是该图的最小工作示例,用户可以在该图之间进行对数刻度和线性刻度之间的切换。
=
我在If
列表中添加了两条迹线,以显示如何也可以从图中添加或删除迹线。每个import plotly
import plotly.graph_objs as go
x = [1, 2, 3]
y = [1000, 10000, 100000]
y2 = [5000, 10000, 90000]
trace1 = go.Bar(x=x, y=y, name='trace1')
trace2 = go.Bar(x=x, y=y2, name='trace2', visible=False)
data = [trace1, trace2]
updatemenus = list([
dict(active=1,
buttons=list([
dict(label='Log Scale',
method='update',
args=[{'visible': [True, True]},
{'title': 'Log scale',
'yaxis': {'type': 'log'}}]),
dict(label='Linear Scale',
method='update',
args=[{'visible': [True, False]},
{'title': 'Linear scale',
'yaxis': {'type': 'linear'}}])
]),
)
])
layout = dict(updatemenus=updatemenus, title='Linear scale')
fig = go.Figure(data=data, layout=layout)
plotly.offline.iplot(fig)
的{{1}}中的data
列表可以对此进行控制。