小编Bla*_*ski的帖子

在循环seaborn图中共享次要y轴

我正在尝试在循环的同一行中绘制一些带有辅助 y 轴的图。我希望它们在第一个图的左侧只有一个主 y 轴,在最后一个图的右侧只有一个辅助 y 轴。到目前为止,我成功地通过子图的 sharey = True 属性完成了第一件事,但我在辅助轴上遇到了麻烦。

for r in df.Category1.sort_values().unique():
    dfx = df[df['Category1'] == r]
    fig, axes = plt.subplots(1,3, figsize = (14,6), sharey=True)
    for (n, dfxx), ax in zip(dfx.groupby("Category2"), axes.flat): 
        ax1 = sns.barplot(x = dfxx['Month'], y = dfxx['value1'], hue = dfxx['Category3'], ci = None, palette = palette1, ax=ax)
        ax2 = ax1.twinx()
        ax2 = sns.pointplot(x = dfxx['Month'], y=dfxx['value2'], hue = dfxx['Category3'], ci = None, sort = False, legend = None, palette = palette2) 

plt.tight_layout()
plt.show()
Run Code Online (Sandbox Code Playgroud)

因此,正如您所看到的循环的一次迭代,它在左侧只有一个主 …

python matplotlib seaborn

5
推荐指数
1
解决办法
3799
查看次数

标签 统计

matplotlib ×1

python ×1

seaborn ×1