matplotlib - Python Hexbin marginals offset from image produced -
i have simple question. when using python hexbin plot option on spatial data (ra, , dec x , y) want see marginals on side. happily there simple option 'marginals = true'....
unhappily, can see below... x-axis marginals visibly offset hexagon produced image. have tried adjusting parameters marginals on x-axis appear offset image (and there never seems problem in y), ideas appreciated. please see code , image below, in advance!
fig5=plt.figure(5) ax=fig5.add_subplot(111) imageh=plt.hexbin(radeg[corel], decdeg[corel], extent=[np.min(radeg[corel]), np.max(radeg[corel]), np.min(decdeg[corel]), np.max(decdeg[corel])], alpha=0.7, gridsize=20, marginals=true, vmin=5, vmax=105, cmap=get_cmap("jet"), mincnt=5) ax.axis([305,275,-40,-25]) cbar=plt.colorbar(imageh,extend='max') cbar.set_label(r'$\mathrm{counts}$',fontsize=18) ax.set_xlabel(r'$\mathrm{ra}$',fontsize=20) ax.set_ylabel(r'$\mathrm{dec}$',fontsize=18) plt.show()
-- per request add data test with..... data rather lengthy , unwieldily, here standalone version illustrates problem. altered version 'hooked' posted in regard different hexbin question.
def generate_data(n): """make random, correlated x & y arrays""" points = np.random.multivariate_normal(mean=(0,0), cov=[[0.4,9],[9,10]],size=int(n)) return points if __name__ =='__main__': color_map = plt.cm.spectral_r n = 1e4 points = generate_data(n) xbnds = np.array([-20.0,20.0]) ybnds = np.array([-20.0,20.0]) extent = [xbnds[0],xbnds[1],ybnds[0],ybnds[1]] fig=plt.figure(figsize=(10,9)) ax = fig.add_subplot(111) x, y = points.t image = plt.hexbin(x,y,cmap=color_map,gridsize=20,marginals=true,extent=extent,mincnt=1,bins='log') ax.set_xlim(xbnds) ax.set_ylim(ybnds) plt.grid(true) cb = plt.colorbar(image,spacing='uniform',extend='max') plt.show()
this code gives similar image, time marginals offset in x , y direction, integral should in 1 direction, on other variable, i.e. rows , columns. in theory expect marginal on side every row , column have data in.
Comments
Post a Comment