matplotlib.pyplot.imshow:使用属性“ sharex”和“ sharey”时,删除图中的空白
问题内容:
我有一个问题,类似于这里发布的问题。不同之处在于,当我绘制两个通过sharex
和sharey
属性共享轴的子图时,在图区域内会出现多余的空白。设置后,空白仍然存在autoscale(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, 1, 2, sharex=ax, sharey=ax) # adding sharex and sharey
ax2.imshow(np.random.random((10,10)))
ax2.autoscale(False)
plt.show()
产生此图像。
我也尝试过了,ax.set_xlim(0, 10)
并ax.set_xbound(0, 10)
按照这里的建议,但无济于事。如何摆脱多余的空格?任何想法,将不胜感激。
问题答案: