Rescale axis on Seaborn JointGrid KDE marginal plots

旧城冷巷雨未停 提交于 2019-12-23 05:39:08

问题


I'm trying to create a seaborn JointGrid object with scatter+contours in the joint_plot and KDEs in the marginals. This gets me pretty close, but the y-axis marginal doesn't scale appropriately. What's the best way to manually rescale the marginal axes? Thanks in advance!

f = p.figure()
ax = f.add_subplot(111)
g = sns.JointGrid(xdata, ydata, xlim=(0,1), ylim=(0,1))
g.plot_joint(sns.kdeplot, shade=True, cmap="Greys", n_levels=10)
g.plot_joint(p.scatter, color='#e74c3c', s=1.5)
g.plot_marginals(sns.kdeplot, color="black", shade=True)
g.ax_joint.collections[0].set_alpha(0)
g.set_axis_labels(r'$\frac{\chi_{0}^2-\chi_{\mathrm{null},1}^2{\chi_{0}^2}$', r'$\frac{\chi_{0}^2-\chi_{\mathrm{null},4}^2}{\chi_{0}^2}$')
p.gcf().subplots_adjust(bottom=.15)
p.gcf().subplots_adjust(left=.15)
p.savefig('something')

This being a new account, I don't have the reputation to post an image - a link to my attempt is here -> http://i.imgur.com/9iG860U.png


回答1:


You can control this by accessing the y-marginal axes using g.ax_marg_y. From there, you can control the axes limits in the usual matplotlib way. In this case, you want to adjust the xlim:

g.ax_marg_y.set_xlim(0,xmax)

where xmax is the number you need to manually change.

If you need to, you can find the current xmax using get_xlim():

xmin, xmax = g.ax_marg_y.get_xlim()

Then you could just increase xmax by some multiple. For example:

xmin, xmax = g.ax_marg_y.get_xlim()
g.ax_marg_y.set_xlim(xmin,xmax*2)


来源:https://stackoverflow.com/questions/36191906/rescale-axis-on-seaborn-jointgrid-kde-marginal-plots

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!