在Seaborn JointGrid KDE边缘图上重新调整轴

时间:2016-03-24 01:51:13

标签: python matplotlib seaborn

我正在尝试使用joint_plot中的散点+轮廓和边距中的KDE创建一个seaborn JointGrid对象。这让我非常接近,但是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, 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')

这是一个新帐户,我没有发布图片的声誉 - 我尝试的链接就在这里 - > http://i.imgur.com/9iG860U.png

enter image description here

1 个答案:

答案 0 :(得分:3)

您可以使用matplotlib访问y边缘轴来控制此操作。从那里,您可以通常xlim方式控制轴限制。在这种情况下,您要调整g.ax_marg_y.set_xlim(0,xmax)

xmax

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

如果需要,您可以使用get_xlim()找到当前的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) 增加几倍。例如:

{{1}}