增加FacetGrid图上行之间的空间 [英] Increase space between rows on FacetGrid plot

查看:31
本文介绍了增加FacetGrid图上行之间的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码创建了可以在图片中看到的图:

I've the following code which creates the plot you can see in the picture:

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)

如您在图片中看到的,问题是x刻度折叠起来并带有下面的col名称.为了解决此问题,增加此空间的正确方法是什么?

The problem, as you can see in the picture, is that the x ticks collapse with the col name below. What is the proper way to increase this space in order to fix this?

推荐答案

紧凑的布局

您可以使用 tight_layout 自动调整间距

g.fig.tight_layout()

或者,如果您将 matplotlib.pyplot 导入为 plt

or, if you have matplotlib.pyplot imported as plt,

plt.tight_layout()

子图调整

您可以使用 plt.subplots_adjust 手动设置子图之间的间距,

subplots adjust

You can use plt.subplots_adjust to manually set the spacings between subplots,

plt.subplots_adjust(hspace=0.4, wspace=0.4)

其中hspace为空间高度,wspace为空间宽度方向.

where hspace is the space in height, and wspace is the space width direction.

您也可以在 FacetGrid 初始化中使用 gridspec_kws

You could also use gridspec_kws in the FacetGrid initialization,

g = sns.FacetGrid(data, ... , gridspec_kws={"wspace":0.4})

但是,只有在未设置 col_wrap 的情况下,才可以使用此选项.(因此,在该问题的特定情况下,这可能不是一个选择.)

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).

这篇关于增加FacetGrid图上行之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆