作者DRLai (苏打)
看板Python
标题[问题] plotly 多层绘图问题
时间Tue Oct 30 18:28:13 2018
python 3.7 版
各位版友好
最近想要将多张图表透过 plotly 呈现
程式大概如下:
from plotly import tools
import plotly.graph_objs as go
trace1 = go.Bar(...)
trace2_1 = go.Scatter(...)
trace2_2 = go.Scatter(...)
trace2_3 = go.Scatter(...)
trace2 = [trace2_1, trace2_2, trace2_3]
单独绘制 trace1 or trace2 都是正常的
但我想要将所有资料呈现在同个画面
(trace1, trace2 的x轴共用)
fig = tools.make_subplots(rows=2, cols=1, specs=[[{}],[{}]],
shared_xaxes=True, shared_yaxes=True,
vertical_spacing=0.001)
fig.append_trace(trace1 , 1, 1)
fig.append_trace(trace2 , 2, 1) <-- 失败
fig.append_trace(trace2_1, 2, 1) <-- 成功
看起来是 specs 描述上的错误
但我尝试修改成 [[{}],[{},{},{}]] 等方式也失败
想请问 specs 该如何描述才能让程式认得多层的图形呢
另外能否在滑鼠移动时同时显示不同 trace 的数值
(例如
https://plot.ly/python/axes/ ,但改用 subplots 的方式)
感谢~
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 118.169.80.35
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1540895296.A.2ED.html
1F:→ DRLai: 第一题自问自答 ... 改用 overlay 10/30 18:44
2F:推 jumptoswim: subfig should work 10/31 11:42
3F:→ jumptoswim: sorry, i mean subplot 10/31 11:43