Python 在matplotlib中调整/拉伸二维直方图,并根据x-y的大小调整存储箱的数量?

Python 在matplotlib中调整/拉伸二维直方图,并根据x-y的大小调整存储箱的数量?,python,numpy,matplotlib,2d,histogram,Python,Numpy,Matplotlib,2d,Histogram,我正在制作一个二维柱状图,如下所示: 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

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

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中的箱子显示得更宽?如果有代码自动将其拉伸到正常的图形纵横比,那将是最佳的

plt.imshow(Hmasked.T,extent=extent,interpolation='nearest',origin='lower', aspect='auto')