python - 从 matplotlib imshow 的边框中删除所有空格
问题描述
我正在尝试为一组绘图设置动画,但由于某种原因,从生成的图像中的绘图边框中删除空格的方法imshow()
不起作用。以下是一些示例和生成的图像:
figsize=(10,10)
fig, ax = plt.subplots(figsize=figsize)
fig.tight_layout()
fig.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=None, hspace=None)
img = ax.imshow(np.random.normal(0,2,(200,200)), animated = True)
这显然仍然有边界、轴、空白等。我可以删除tight_layout()
orsubplots_adjust()
并且它不会显着改变行为。我做了一些挖掘,在这里找到了几个答案,建议如下:
figsize=(4,4)
fig, ax = plt.subplots(figsize=figsize)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
img = ax.imshow(np.random.normal(0,2,(200,200)), animated = True,aspect = 'auto')
从这个页面上看可能不是很明显,但如果你看看这里的图像如何与上面代码框的左边界对齐,你会发现仍然有空白。尝试使用tight_layout()
orsubplots_adjust()
在这种情况下也无济于事。似乎必须有可能完全去除白色边界,但我不清楚还有什么可以尝试的。
编辑:评论中建议了以下修复,来自不同的帖子:
fig, ax = plt.subplots(facecolor='purple')
fig.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=None, hspace=None)
ax.margins(0,0)
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.gca().yaxis.set_major_locator(plt.NullLocator())
img = ax.imshow(np.random.normal(0,2,(200,200)), animated = True)
我使用紫色背景来指示图形结束的位置。这导致以下输出:
这也没有奏效。
提到我正在使用 Spyder IDE 也可能很有用,它可能有一些我不知道的额外特质。
解决方案
推荐阅读
- c - 如何从重音字符中获取 utf-8 重音代码?
- laravel - laravel api中文件中的双倍时间规范
- node.js - 如何使用选项启动 Nodejs 服务器?
- angular - 没有找到 exportAs 'ngModel' 的指令
- python - 在 virtualenv 上安装 pip
- fortran - 提高 Fortran 中“sum()”命令的准确性
- r - 根据 R 数据框中的更改位置或日期分配事件编号
- amazon-web-services - AWS EC2 流量 1TB 产生的成本是多少?(AWS EC2 免费套餐)
- python - 在 MySQL 中存储印地语
- google-apps-script - 有没有什么地方或方法可以在谷歌应用脚本中存储私钥?