我有一个问题,类似于这里发布的问题。不同之处在于,当我绘制两个通过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()
导致this图像的结果。
我也尝试过ax.set_xlim(0, 10)
和ax.set_xbound(0, 10)
,根据here的建议,但都没有用。如何去掉额外的空白?任何想法都将不胜感激。
imshow()
中的aspect ='auto'
来添加另一种方式。 - PlasmaBinturong