【发布时间】:2018-06-16 07:08:17
【问题描述】:
我正在使用 plotly 离线模式创建具有公共 x 轴的垂直堆叠子图(1 列和 10 行)。我希望可以选择使用复选框或下拉菜单来显示/隐藏子图。
以下是我正在使用的示例代码。基本上我需要在渲染后隐藏一些子图。例如,在 5 个子图中,我想隐藏 plot2 和 plot4。一旦隐藏,应该只显示 3 个子图。所以不要只是试图隐藏数据系列,因为那样仍然会保留子图空间。
import plotly.offline as po
import plotly.graph_objs as go
from plotly import tools
fig = tools.make_subplots(rows=5, cols=1, shared_xaxes=True,
subplot_titles=['plot1', 'plot2', 'plot3', 'plot4', 'plot5'])
xval = [i for i in range(10)]
for p in range(5):
yval = [x**(p+1) for x in xval]
fig.append_trace(go.Scatter(mode='lines', x=xval, y=yval,
name='y = x^{}'.format(p+1)), p+1, 1)
fig['layout'].update(title='Test', height=1000, width=1500, showlegend=True, margin=go.Margin(l=150))
po.plot(fig, filename='sample', auto_open=True)
【问题讨论】:
-
您是否使用python(只是想确认)如果可能还提供一些示例代码?
-
我正在使用 python。
-
我已经更新了这个问题的更多细节,希望这能澄清我的问题。