Seaborn JointGrid hexplot: aspect ratio issue

1.8k views Asked by At

I'm trying to create a JointGrid plot but I'm having some trouble with getting the aspect ratio right. The relevant code and the figure are attached below. Not sure what I'm doing wrong.

fig = plt.figure()
sns.set_style("ticks")
g = sns.JointGrid(X, Y, xlim=[0, max(X)], ylim=[0, max(Y)])
g.plot_marginals(sns.distplot, color=".5")
g.plot_joint(plt.hexbin, bins='log', gridsize=30, cmap=color)

And the output figure: enter image description here

I'm not sure what I'm doing wrong; I looked at this: https://github.com/mwaskom/seaborn/issues/271 but the fix there didn't work.

Thank you!

1

There are 1 answers

0
brokenseas On BEST ANSWER

I figured it out; posting my solution here just in case anyone has the same issue in the future.

fig = plt.figure()
sns.set_style("ticks")
g = sns.JointGrid(X, Y)
g.plot_marginals(sns.distplot, color=".5")
g.plot_joint(plt.hexbin, bins='log', gridsize=30, cmap=color, extent=[0, np.max(X), 0, np.max(X)])

I essentially just set the extents for both of them to be equal to the maximum value of the X array (which has a higher maxima than Y, causing the weird aspect ratio).

The end result is this:

enter image description here