python – matplotlib.pyplot.imshow:在使用属性“sharex”和“sharey”时删除图

我有一个类似于一个发布的
here的问题.不同的是,当我绘制通过sharex和sharey属性共享轴的两个子图时,我会在绘图区域内得到不需要的空格.即使设置自动调整(False)后,空格仍然会持续.例如,使用与上述帖子的答案相似的代码:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(2,1,1)
ax.imshow(np.random.random((10,10)))
ax.autoscale(False)
ax2 = fig.add_subplot(2,2,sharex=ax,sharey=ax)   # adding sharex and sharey
ax2.imshow(np.random.random((10,10)))
ax2.autoscale(False)
plt.show()

导致this图像.

我也按照建议here尝试了ax.set_xlim(0,10)和ax.set_xbound(0,10),但是没有效果.如何摆脱额外的白色空间?任何想法将不胜感激.

解决方法

如建议
here,补充说:

ax.set_adjustable('box-forced')
ax2.set_adjustable('box-forced')

解决问题.

(documentation)

dawei

【声明】:淮南站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。