Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matplotlib 使用seaborn jointgrid绘制日志图_Matplotlib_Seaborn_Loglog - Fatal编程技术网

Matplotlib 使用seaborn jointgrid绘制日志图

Matplotlib 使用seaborn jointgrid绘制日志图,matplotlib,seaborn,loglog,Matplotlib,Seaborn,Loglog,我正在尝试使用seaborn JointGrid对象创建一个日志图,其中包含与每个轴相关联的KDE和直方图。这让我非常接近,但直方图箱不能很好地转换为日志空间。有没有一种不用重新创建边缘轴就可以轻松完成的方法 import seaborn as sns import matplotlib.pyplot as plt import numpy as np data = sns.load_dataset('tips') g = sns.JointGrid('total_bill', 'tip',

我正在尝试使用seaborn JointGrid对象创建一个日志图,其中包含与每个轴相关联的KDE和直方图。这让我非常接近,但直方图箱不能很好地转换为日志空间。有没有一种不用重新创建边缘轴就可以轻松完成的方法

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')

对于日志直方图,我发现设置您自己的存储箱通常很有用

然后在
\u 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')

我想你不会比现在更接近了。我认为
jointplot
本身应该能更好地处理这一点,但我一直在谨慎地添加它,因为我不确定人们到底希望什么最有意义。你能说说你喜欢直方图是什么样子吗?原木空间中的等宽条?是的--等宽条会很棒。我知道如何手动使用ax.hist和np.logspace实现这一点,但对于seaborn,我想我将继续在数据帧中记录数据,然后将10^x应用于轴标签,作为解决方法。作为旁注,我不明白为什么仅仅设置ax=g.ax_关节ax.set_xscale('log')ax.set_yscale('log')不会自动设置边缘轴?谢谢你的回复,这是一个很棒的包裹!这是令人惊讶的。seaborn在设置
JointGrid
时共享这些轴,因此这表明matplotlib中存在不一致。seaborn的较新版本允许这样做,而无需调用日志空间:
g.plot\u marginals(sns.histplot,log\u scale=True,bin=100,kde=True)
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')