首页 > 解决方案 > seaborn 子图的图例和标题大小的排列

问题描述

我对图例的排列和字体大小有疑问。正如您在图片中看到的,图例在图表中,而不是在它旁边(它应该在右侧)。我还想更改标题和轴的字体大小。不幸的是,我只能在它们不相邻放置的情况下这样做。有谁知道这如何工作?错误可能是由于我制作子图的方式造成的吗?

非常感谢!

#Create Boxplots for beliefed ranks 
f, axes = plt.subplots(1, 2)

figure_Grank = sns.boxplot(x='Treatment',y='Believed Rank within own Gender',data=df_fig, hue="sex", palette='vlag_r', ax=axes[0]).set(title="Beliefed Rank within own Gender")
plt.legend(title="Sex", bbox_to_anchor=(0.75, 1), loc=2, borderaxespad=0., fancybox=True)


figure_rank = sns.boxplot(x='Treatment',y='Believed Rank',data=df_fig[df_fig["Period"]==4], hue="sex", palette='vlag_r', ax=axes[1]).set(title="Beliefed Rank whithin own Group")
plt.legend(title="Sex", bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0., fancybox=True)



plt.subplots_adjust(left=0,
                    bottom=0.2, 
                    right=2, 
                    top=1.2, 
                    wspace=0.2, #this is the horizontal space between the diagrams
                    hspace=4) #this is the vertical space between the diagrams  #0.8   

在此处输入图像描述

标签: pythonseabornlegenddiagramsubplot

解决方案


推荐阅读