python - Resize/stretch 2d histogram in matplotlib with x-y dependent number of bins? -
i making 2d histogram follows:
import matplotlib plt import numpy 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 value of 0 extent = [xedges[0], xedges[-1], yedges[0], yedges[-1] ] plt.imshow(hmasked.t,extent=extent,interpolation='nearest',origin='lower') plt.show()
this has 50 bins in x , 150 bins in y. resulting plot narrow in x , tall in y. how stretch out plot in x bins in x allowed appear wider? if there code automatically stretches normal figure aspect ratio, optimal.
plt.imshow(hmasked.t,extent=extent,interpolation='nearest',origin='lower', aspect='auto')
Comments
Post a Comment