无法在Python中生成正确的图
因此,我一直在尝试在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 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将
plt.axis('quare')
更改为plt.axis('scaled')
。如 documentation>Try changing
plt.axis('equal')
toplt.axis('scaled')
. As the documentation says: