为了账号安全,请及时绑定邮箱和手机立即绑定

Plot.ly:共享 X 轴的子图的不同高度

Plot.ly:共享 X 轴的子图的不同高度

狐的传说 2021-07-06 16:00:00
背景具有相同高度 (✘) 的不同子图 (✔)我可以创建一个带有共享 X 轴的子图(示例改编自Plot.ly doc),子图之间有适当的分隔,并且您可以通过subplot_titles以下方式为每个子图插入特定标题:from plotly import toolsimport plotly.plotly as pyimport plotly.graph_objs as gotrace1 = go.Scatter(    x=[0, 1, 2],    y=[10, 11, 12])trace2 = go.Scatter(    x=[2, 3, 4],    y=[100, 110, 120],)trace3 = go.Scatter(    x=[3, 4, 5],    y=[1000, 1100, 1200],)fig = tools.make_subplots(rows=3, cols=1, specs=[[{}], [{}], [{}]],                          shared_xaxes=True, shared_yaxes=True,                          vertical_spacing=0.1, subplot_titles=('subtitle 1',                           'subtitle 2', 'subtitle 3'))fig.append_trace(trace1, 3, 1)fig.append_trace(trace2, 2, 1)fig.append_trace(trace3, 1, 1)fig['layout'].update(height=600, width=600, title='Subplots with Shared X-Axes')py.plot(fig, filename='subplots-shared-xaxes')
查看完整描述

1 回答

?
慕丝7291255

TA贡献1859条经验 获得超6个赞

Kully 在PR #1245 中解决了这个错误,并dash v3.4.0.

//img1.sycdn.imooc.com//60f7ddba0001573a05260506.jpg

以下代码 - 仅使用 3 个子图row_width=[0.2, 0.4, 0.2]- 因此应该可以完美运行:


from plotly import tools

import plotly.plotly as py

import plotly.graph_objs as go


trace1 = go.Scatter(

    x=[0, 1, 2],

    y=[10, 11, 12]

)

trace2 = go.Scatter(

    x=[2, 3, 4],

    y=[100, 110, 120],

)

trace3 = go.Scatter(

    x=[3, 4, 5],

    y=[1000, 1100, 1200],

)

fig = tools.make_subplots(rows=3, cols=1,

                          shared_xaxes=True,

                          vertical_spacing=0.1,

                          subplot_titles=('subtitle 1', 'subtitle 2', 'subtitle 3'),

                          row_width=[0.2, 0.4, 0.2]

                         )


fig.append_trace(trace1, 3, 1)

fig.append_trace(trace2, 2, 1)

fig.append_trace(trace3, 1, 1)


fig['layout'].update(height=600, width=600, title='Subplots with Shared X-Axes')

go.FigureWidget(fig)


查看完整回答
反对 回复 2021-07-21
  • 1 回答
  • 0 关注
  • 437 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号