在matplotlib中调整/拉伸二维柱状图的大小和xy相关的箱子数?

2024-06-25 06:53:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我制作了一个二维柱状图,如下所示:

import matplotlib as plt
import numpy as np

hist,xedges,yedges = np.histogram2d(x,y,bins=[50,150],range=[[0,50],[0,150]])
Hmasked = np.ma.masked_where(hist==0,hist) # Mask pixels with a value of zero
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1] ]
plt.imshow(Hmasked.T,extent=extent,interpolation='nearest',origin='lower')
plt.show()

这在x中有50个箱子,在y里有150个箱子。得到的图在x是窄的,在y上是高的。a如何在x中展开图,以便x中的箱子看起来更宽?如果有代码可以自动将其拉伸到正常的图形纵横比,那将是最佳选择。在


Tags: importnumpymatplotlibasnppltextenthist