Rod*_*d0n 4 matplotlib seaborn
我有以下代码创建了可以在图片中看到的图:
g = sns.FacetGrid(data, col="Provincia",col_wrap=6,size=2.5)
g.map(sns.barplot, "Anio", "Diff");
g.set_axis_labels("Año", "Porcentaje de aumento");
for ax in g.axes.flat:
_ = plt.setp(ax.get_yticklabels(), visible=True)
_ = plt.setp(ax.get_xticklabels(), visible=False)
_ = plt.setp(ax.get_xticklabels()[0], visible=True)
_ = plt.setp(ax.get_xticklabels()[-1], visible=True)
Run Code Online (Sandbox Code Playgroud)
如您在图片中所看到的,问题是x刻度折叠起来并带有下面的col名称。为了解决此问题,增加此空间的正确方法是什么?
Imp*_*est 10
您可以tight_layout
用来自动调整间距
g.fig.tight_layout()
Run Code Online (Sandbox Code Playgroud)
或者,如果您已将matplotlib.pyplot
导入为plt
,
plt.tight_layout()
Run Code Online (Sandbox Code Playgroud)
You can use plt.subplots_adjust
to manually set the spacings between subplots,
plt.subplots_adjust(hspace=0.4, wspace=0.4)
Run Code Online (Sandbox Code Playgroud)
where hspace
is the space in height, and wspace
is the space width direction.
You could also use gridspec_kws
in the FacetGrid
initialization,
g = sns.FacetGrid(data, ... , gridspec_kws={"wspace":0.4})
Run Code Online (Sandbox Code Playgroud)
However, this can only be used if col_wrap
is not set. (So it might not be an option in the particular case from the question).
归档时间: |
|
查看次数: |
4314 次 |
最近记录: |