无法在Python中生成正确的图

发布于 2025-02-04 11:39:50 字数 879 浏览 2 评论 0原文

因此,我一直在尝试在python中生成一个热图,以使生成的matplotlib图在x和y轴上都没有任何白色边缘,并且相对于x和y轴单元,图形的缩放率必须为1:1。我已经尝试了很多事情,但是到目前为止,我能够取得的最佳成就就是能够删除X轴白色边缘,而不是Y的边缘。这是一个例子: 这就是我得到的: 这就是我想要的: 我想要的“

这是我生成图表的代码:

plt.style.use('classic')
plt.axis('equal')
plt.pcolormesh(x_mesh,y_mesh,intensity)
plt.plot(x,y,linestyle="None",marker='.',markerfacecolor='white')
#plt.colorbar()
#plt.axis('off')
plt.margins(x=0,y=0)
plt.ylim([0,254])
plt.xlim([0,538])
plt.savefig('plottest.png', dpi=144, bbox_inches='tight', pad_inches=0)
plt.show()

任何帮助都将不胜感激!谢谢!

So I have been trying to generate a heatmap in python such that the Matplotlib graph that is generated does not have any white margins in both x and y axes and the graph's scaling must be 1:1 with respect to the x and y axes units. I have tried many things but the best I have been able to achieve so far is able to remove the x axis white margins but not the y one. Here's an example:
This is what I am getting:
This is what I am getting
This is what I want:
This is what I want

Here's the code through which I am generating the graph:

plt.style.use('classic')
plt.axis('equal')
plt.pcolormesh(x_mesh,y_mesh,intensity)
plt.plot(x,y,linestyle="None",marker='.',markerfacecolor='white')
#plt.colorbar()
#plt.axis('off')
plt.margins(x=0,y=0)
plt.ylim([0,254])
plt.xlim([0,538])
plt.savefig('plottest.png', dpi=144, bbox_inches='tight', pad_inches=0)
plt.show()

Any help would be highly appreciated! Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲世九天 2025-02-11 11:39:50

尝试将plt.axis('quare')更改为plt.axis('scaled')。如 documentation>

等于:...在这种情况下可能无法尊重显式数据限制。

Try changing plt.axis('equal') to plt.axis('scaled'). As the documentation says:

equal: ... Explicit data limits may not be respected in this case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文