How to enable and disable the logarithmic scale as a viewer in Plotly?(如何在 Plotly 中启用和禁用对数刻度作为查看器?)
问题描述
我最近在探索 Plotly,我想知道是否有一种方法可以共享绘图并让查看器在对数轴和线性轴之间切换.
I am recently exploring Plotly and I wonder if there is a way for sharing a plot and let the viewer switch between a logarithmic axis and linear axis.
有什么建议吗?
推荐答案
Plotly 有一个 dropdown 功能它允许用户动态更新绘图样式和/或正在显示的轨迹.下面是一个绘图的最小工作示例,用户可以在对数和线性刻度之间切换.
Plotly has a dropdown feature which allows the user to dynamically update the plot styling and/or the traces being displayed. Below is a minimal working example of a plot where the user can switch between a logarithmic and linear scale.
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)
我在 data
列表中添加了两条迹线,以显示如何在绘图中添加或删除迹线.这可以由每个 button
的 updatemenus
中的 visible
列表控制.
I added two traces to the data
list to show how traces can also be added or removed from a plot. This can be controlled by the visible
list in updatemenus
for each button
.
这篇关于如何在 Plotly 中启用和禁用对数刻度作为查看器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Plotly 中启用和禁用对数刻度作为查看器?


基础教程推荐
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 包装空间模型 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01