Plotly中同一X轴和Y轴上的多个条形图

问题描述 投票:2回答:1

我试图在同一个x轴和y轴上绘制多个条形图。我不想要堆叠或分组的条形图。我只想让多个条形图并排显示长x轴,其中x轴刻度重复基于条形图的数量和沿着条形图共享的y轴,并放置在图形的最左侧。

这是我的代码,但它不会产生我想要的输出

import plotly.offline as pyo
import plotly.graph_objs as go
from plotly import tools



trace1 = go.Bar(
    x=[1, 2, 3],
    y=[10, 11, 12]
)
trace2 = go.Bar(
    x=[1, 2, 3],
    y=[100, 110, 120],
)
trace3 = go.Bar(
    x=[1, 2, 3],
    y=[1000, 1100, 1200],
)


fig = tools.make_subplots(rows=3, cols=1, specs=[[{}], [{}], [{}]],
                          shared_xaxes=True, shared_yaxes=True,
                          vertical_spacing=0.001)


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='')

pyo.plot(fig, filename='bar-charts-with-shared-axis.html')

任何帮助,将不胜感激

python plotly plotly-dash plotly-python
1个回答
2
投票

如果我正确理解,你想要:Your output

码:

import plotly.offline as pyo
import plotly.graph_objs as go
from plotly import tools

trace1 = go.Bar(
    x=[1, 2, 3],
    y=[10, 11, 12]
)
trace2 = go.Bar(
    x=[1, 2, 3],
    y=[100, 110, 120],
)
trace3 = go.Bar(
    x=[1, 2, 3],
    y=[1000, 1100, 1200],
)

fig = tools.make_subplots(rows=1, cols=3,
                          shared_xaxes=True, shared_yaxes=True,
                          vertical_spacing=0.001)

fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 1, 2)
fig.append_trace(trace3, 1, 3)

fig['layout'].update(height=600, width=600, title='')

pyo.plot(fig, filename='bar-charts-with-shared-axis.html')
© www.soinside.com 2019 - 2024. All rights reserved.