如何删除matplotlib子图中的填充/边框 [英] How to remove padding/border in a matplotlib subplot

查看:116
本文介绍了如何删除matplotlib子图中的填充/边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The second subplot is just the first image with an overlay ploted. In the second plot there appears to have white padding/boarder. How do I remove this padding/whitespace?

为完整起见,以下是执行绘图的代码片段:

For completness, here is the fragment of code that performs the plotting:

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向绘图数据添加一些边距.我无法测试它,因为它没有您的 image_labelscenters,但这通常应该可以工作:

By default, Matplotlib adds some margin to plotted data. I cant test it because it dont have your image_labels and centers, but this should normally work:

ax[1].autoscale_view('tight')

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

An alternative would be to manually set the xlim and ylim of the axes:

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

这篇关于如何删除matplotlib子图中的填充/边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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