【问题标题】:matplotlib no space between some axesmatplotlib 某些轴之间没有空格
【发布时间】:2020-03-06 06:27:48
【问题描述】:

使用 matplotlib 我试图在一个网格中绘制 3 个图表,然后是一个具有 3 个不同 Y 范围但 X 比例相同的图表。我可以通过使用hspace 命令来实现这一点,但它会影响整个文档。是否可以只针对一张图表进行?

我当前的代码:

fig = plt.figure(figsize=(11.69,16.53))
gs = fig.add_gridspec(5, 2)
# chart 1,2,3
fig.add_subplot(gs[0, :])
fig.add_subplot(gs[1, 0])
fig.add_subplot(gs[1, 1])
# chart 4
ax = fig.add_subplot(gs[2, :])
ax.xaxis.set_visible(False) 
ax = fig.add_subplot(gs[3, :])
ax.xaxis.set_visible(False) 
fig.add_subplot(gs[4, :])
# adjust and save
plt.subplots_adjust(hspace=.0)
fig.savefig('report.pdf')

生产:

all charts without spacing

【问题讨论】:

    标签: python matplotlib spacing


    【解决方案1】:

    你需要使用

    plt.tight_layout(pad=3.0)
    

    用另一个数字替换填充值以增加/减少间距。

    【讨论】:

    • 我在 plt.subplots_adjust(hspace=.0) 和 fig.savefig('report.pdf') 之间添加了它,结果是所有子图都是间隔的(就像根本没有 hspace),但是 3底部子图需要是一个图表
    猜你喜欢
    • 2014-05-01
    • 2015-12-29
    • 1970-01-01
    • 1970-01-01
    • 2016-08-03
    • 2021-08-12
    • 1970-01-01
    • 2017-06-22
    相关资源
    最近更新 更多