【发布时间】:2021-12-02 02:36:35
【问题描述】:
我正在尝试使用 plotly 绘制一个子图,其中我有一些线图,并且子图中的所有图都需要共享相同的 x 轴,如图所示。
fig = make_subplots(
rows=5,
cols=1,
vertical_spacing=0.05,
subplot_titles=['Count / Anzahl', 'min_nValue', 'max_nValue', 'avg_nValue', 'sum_nValue'],
shared_xaxes=True,
)
fig.append_trace(go.Scatter(
x=df_dict_nValueAgg['Erste_15_Minuten']['KurzName'],
y=df_dict_nValueAgg['Erste_15_Minuten']['min_nValueNorm'],
name = "min_nValue_" + "Erste_15_Minuten",
mode='lines+markers',
#legendgroup = 2
), row=2, col=1)
fig.append_trace(go.Scatter(
x=df_dict_nValueAgg['Erste_15_Minuten']['KurzName'],
y=df_dict_nValueAgg['Erste_15_Minuten']['max_nValueNorm'],
name = "max_nValue_" + "Erste_15_Minuten",
mode='lines+markers',
#legendgroup = 2
), row=2, col=1)
.
.
.
# couple of plots more
.
.
fig.update_layout(
legend_orientation="v",
height=1000,
width=2000,
title_text=currentEventTitle+pastEventTitle+nAttributes,
)
fig.update_xaxes(tickangle=45)
fig.write_image('fig1.png')
fig.show()
这给了我这个数字
最后三个图产生潦草的线条。现在我明白了,由于我基于列的四个值(即 Erste_15_Minuten、Zweite_15_Minuten、Dritte_15_Minuten 和 Letzte_15_Minuten)过滤数据,因此最后三个图的 xticks 数量不相等或可能以不同的顺序排列。有没有办法可以避免这个问题?切换到条形图可以避免这个问题,但我只需要使用线图。提前谢谢你。
【问题讨论】:
-
您的示例代码不包含任何数据或 scribble 图的生成方式。看来您的 x 轴是一个分类的,我认为您需要通过将 NaN 放在 y 轴值中来“过滤”,并且 x 轴在所有子图中保持一致
标签: python dataframe plotly data-visualization plotly-python