Seaborn JointGrid KDE 边缘图上的重新缩放轴 [英] Rescale axis on Seaborn JointGrid KDE marginal plots

查看:49
本文介绍了Seaborn JointGrid KDE 边缘图上的重新缩放轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个seaborn JointGrid 对象,在joint_plot 和边缘的KDE 中使用散布+轮廓.这让我非常接近,但 y 轴边际没有适当缩放.手动重新缩放边缘轴的最佳方法是什么?提前致谢!

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,颜色=黑色",阴影=真)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('东西')

这是一个新帐户,我没有发布图片的声誉 - 我尝试的链接在这里 ->

解决方案

您可以通过使用 g.ax_marg_y 访问 y 边际轴来控制这一点.从那里,您可以以通常的 matplotlib 方式控制轴限制.在这种情况下,您要调整 xlim:

g.ax_marg_y.set_xlim(0,xmax)

其中 xmax 是您需要手动更改的数字.

如果需要,您可以使用 get_xlim() 找到当前的 xmax:

xmin, xmax = g.ax_marg_y.get_xlim()

然后你可以将 xmax 增加一些倍数.例如:

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

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

解决方案

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)

这篇关于Seaborn JointGrid KDE 边缘图上的重新缩放轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆