Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Hexbin marginals offset from image produced
    primarykey
    data
    text
    <p>I have a hopefully simple question. When using the python hexbin plot option on some spatial data (Ra, and Dec are x and y) I also want to see the marginals on the side. Happily there is a simple option 'marginals = True'....</p> <p>Unhappily, as you can see below... the x-axis marginals are visibly offset from the hexagon produced image. I have tried adjusting parameters but the marginals on the x-axis always appear offset to the image (and there never seems to be a problem in y), any ideas would be appreciated. Please see the code and image below, Thanks in advance! </p> <pre><code>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() </code></pre> <p><img src="https://i.stack.imgur.com/zHBnw.png" alt="The counts image produced by hexbin"></p> <p>-- per request that I add data to test with..... my data is rather lengthy and unwieldily, but here is a standalone version that illustrates the problem. This is a altered version from 'Hooked' who posted in regard to a different hexbin question.</p> <pre><code>def generate_data(n): """Make random, correlated x &amp; 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() </code></pre> <p>This code gives a similar image, but this time the marginals are offset in the x and y direction, the integral should be just in one direction, over the other variable, i.e. rows and columns. In theory I would expect a marginal on the side for every row and column I have data in. </p> <p><img src="https://i.stack.imgur.com/90FY1.png" alt="marginals from new code image"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload