本文介绍了Seaborn Jointgrid的对数-对数图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 seaborn JointGrid 对象创建一个日志图,其中包含与每个轴关联的 KDE 和直方图.这使我非常接近,但是直方图箱无法很好地转换为对数空间.有没有一种方法可以轻松做到这一点而不必重新创建边缘轴?
I'm trying to create a loglog plot with a KDE and histogram associated with each axis using a seaborn JointGrid object. This gets me pretty close, but the histogram bins do not translate well into logspace. Is there a way to do this easily without having to recreate the marginal axes?
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
data = sns.load_dataset('tips')
g = sns.JointGrid('total_bill', 'tip', data)
g.plot_marginals(sns.distplot, hist=True, kde=True, color='blue')
g.plot_joint(plt.scatter, color='black', edgecolor='black')
ax = g.ax_joint
ax.set_xscale('log')
ax.set_yscale('log')
g.ax_marg_x.set_xscale('log')
g.ax_marg_y.set_yscale('log')
推荐答案
对于日志直方图,我发现使用 np.logspace()
.
For log histograms I find generally useful to set your own bins with np.logspace()
.
mybins=np.logspace(0,np.log(100),100)
然后只需在 _marginals
data = sns.load_dataset('tips')
g = sns.JointGrid('total_bill', 'tip', data,xlim=[1,100],ylim=[0.01,100])
g.plot_marginals(sns.distplot, hist=True, kde=True, color='blue',bins=mybins)
g.plot_joint(plt.scatter, color='black', edgecolor='black')
ax = g.ax_joint
ax.set_xscale('log')
ax.set_yscale('log')
g.ax_marg_x.set_xscale('log')
g.ax_marg_y.set_yscale('log')
这篇关于Seaborn Jointgrid的对数-对数图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!