如何使用plt.figure和add_subplot放大seaborn boxplot?

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

[有很多使用无花果放大图的示例,ax = plt.subplots()。

但是我有一个代码,我正在使用fig = plt.figure(figsize =(8,11)),因此有fig.add_subplot(311)和fig.add_subplot(312)和fig.add_subplot(313)。

如果愿意,如何放大这些特定子图中之一的区域?

在我的情况下,每个子图都是一个sns.boxplot。

fig = plt.figure(figsize=(8,11))

fig.add_subplot(312) #This is the second subplot of the three plots 

bp2 = sns.boxplot(y='SR [-]', x='Spin Setup', 
             data=df, 
             palette="colorblind",
             hue='Rubber', 
             width=0.5,
             fliersize=3)

请参阅我的三个情节中的第二个情节的图片。我想以3和6的xtick值放大框线图。

the three plots

python plot zoom seaborn boxplot
1个回答
0
投票

如果您不希望在第二个图中显示spin setup == 0的框,则可以使用df.loc[df['Spin Setup'] != 0排除它们:

bp2 = sns.boxplot(y='SR [-]', x='Spin Setup', 
             data=df.loc[df['Spin Setup'] != 0`], 
             palette="colorblind",
             hue='Rubber', 
             width=0.5,
             fliersize=3)

另一种解决方法是使用bp2.set_xlim(2.5, 6.5)bp2.set_ylim(-1, 0)手动设置y和x轴>

© www.soinside.com 2019 - 2024. All rights reserved.