python – matplotlib.pyplot.imshow:在使用属性“sharex”和“sharey”时删除图
发布时间:2021-02-20 09:25:42 所属栏目:Python 来源:互联网
导读:我有一个类似于一个发布的 here的问题.不同的是,当我绘制通过sharex和sharey属性共享轴的两个子图时,我会在绘图区域内得到不需要的空格.即使设置自动调整(False)后,空格仍然会持续.例如,使用与上述帖子的答案相似的代码: import matplotlib.pyplot as pltimp
我有一个类似于一个发布的 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) (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |