【问题标题】:How to remove padding/border in a matplotlib subplot如何在 matplotlib 子图中删除填充/边框
【发布时间】:2013-04-22 21:38:05
【问题描述】:

第二个子图只是第一个绘制了叠加层的图像。在第二个图中,似乎有白色填充/边界。如何删除此填充/空白?

为了完整起见,这里是执行绘图的代码片段:

fig, ax = plt.subplots(1, 2)
fig.set_size_inches(16, 6, forward=True)
plt.subplots_adjust(0.05, 0.05, 0.95, 0.95, 0.05, 0.05)
ax[0].set_title("Region Labels")
ax[0].imshow(image_labels)

ax[1].set_title("Region Connectivity Graph")
ax[1].imshow(image_labels)
for edge in edges:
    ax[1].plot([centers[edge[0]][0],centers[edge[1]][0]],
             [centers[edge[0]][1],centers[edge[1]][1]]) 
for a in ax:
    a.set_xticks(())
    a.set_yticks(())
plt.show()

【问题讨论】:

    标签: matplotlib


    【解决方案1】:

    默认情况下,Matplotlib 会为绘制的数据添加一些边距。我无法测试它,因为它没有您的image_labelscenters,但这应该正常工作:

    ax[1].autoscale_view('tight')
    

    另一种方法是手动设置轴的 xlim 和 ylim:

    ax[1].set_xlim(0,image_labels.shape[1])
    ax[1].set_ylim(0,image_labels.shape[0])
    

    【讨论】:

      猜你喜欢
      • 2019-04-12
      • 2023-03-11
      • 2022-01-25
      • 2016-05-15
      • 2012-07-23
      • 1970-01-01
      • 2016-05-02
      • 1970-01-01
      • 2017-02-28
      相关资源
      最近更新 更多