【问题标题】:Generating square subplots without gaps between them生成正方形子图,它们之间没有间隙
【发布时间】:2016-08-10 20:29:03
【问题描述】:

我正在尝试使用以下代码在 How to remove gaps between subplots in matplotlib? 上重现 Thucydides411 的示例:

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(8,8)) # Notice the equal aspect ratio
ax = [fig.add_subplot(2,2,i+1) for i in range(4)]

for a in ax:
    a.set_xticklabels([])
    a.set_yticklabels([])
    a.set_aspect('equal')

fig.subplots_adjust(wspace=0, hspace=0)

plt.show()

由于图形大小具有相等的纵横比,我希望子图之间没有间隙。但是,我看到的是以下内容:

虽然没有垂直间隙,但有一个小的横向间隙。任何想法为什么这不像 Thucydides411 那样有效?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    解决它的一种方法是使用tight_layout 而不是subplots_adjust

    fig.tight_layout(h_pad=0, w_pad=0)
    

    结果图现在没有间隙了:

    【讨论】:

      猜你喜欢
      • 2012-05-18
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多