Python 带seaborn的对数lmplot

Python 带seaborn的对数lmplot,python,seaborn,Python,Seaborn,功能lmplot是否可以从Seaborn在对数刻度上绘制? 这是正常比例下的lmplot import numpy as np import pandas as pd import seaborn as sns x = 10**arange(1, 10) y = 10** arange(1,10)*2 df1 = pd.DataFrame( data=y, index=x ) df2 = pd.DataFrame(data = {'x': x, 'y': y}) sns.lmplot('x'

功能
lmplot
是否可以从Seaborn在对数刻度上绘制? 这是正常比例下的lmplot

import numpy as np
import pandas as pd
import seaborn as sns
x =  10**arange(1, 10)
y = 10** arange(1,10)*2
df1 = pd.DataFrame( data=y, index=x )
df2 = pd.DataFrame(data = {'x': x, 'y': y}) 
sns.lmplot('x', 'y', df2)

首先调用seaborn函数。它返回一个
FaceGrid
对象,该对象具有
axes
属性(matplotlib
axes
的二维numpy数组)。抓取
对象并将其传递给调用
df1.plot

import numpy as np
import pandas as pd
import seaborn as sns

x =  10**np.arange(1, 10)
y = 10**np.arange(1,10)*2
df1 = pd.DataFrame(data=y, index=x)
df2 = pd.DataFrame(data = {'x': x, 'y': y})

fgrid = sns.lmplot('x', 'y', df2)    
ax = fgrid.axes[0][0]
df1.plot(ax=ax)        

ax.set_xscale('log')
ax.set_yscale('log')

如果您只想绘制一个简单的回归,那么使用
seaborn.regplot
会更容易。这似乎是可行的(尽管我不确定y轴次网格的位置)

如果您需要将
lmplot
用于其他目的,我会想到这一点,但我不确定x轴刻度会发生什么。如果有人有想法,而这是seaborn中的一个bug,我很乐意修复它:

grid = sns.lmplot('x', 'y', data, size=7, truncate=True, scatter_kws={"s": 100})
grid.set(xscale="log", yscale="log")

根据(可能)任何seaborn图绘制对数图的最简单方法是:

plt.xscale('log')
plt.yscale('log')
在示例中:

import numpy as np
import pandas as pd
import seaborn as sns
x =  10**np.arange(1, 10)
y = 10** np.arange(1,10)*2
df1 = pd.DataFrame( data=y, index=x )
df2 = pd.DataFrame(data = {'x': x, 'y': y}) 
sns.lmplot('x', 'y', df2)
plt.xscale('log')
plt.yscale('log')

如果您不使用facet,那么使用
seaborn.regplot
会更容易。我有点困惑,因为您的代码绘制了两个绘图。你想用seaborn复制第一个情节吗?或者您想在第一个绘图的顶部绘制
lmplot
?@mwaskom第一个绘图不应该在那里。我现在从代码中删除了它。理论上,它应该更简单,您可以只做
fgrid.set(xscale=“log”,yscale=“log”)
,但是由于matplotlib的一些古怪特性和
lmplot
的工作方式,这并没有达到我们想要的效果。感谢您在@mwaskom中的来电。我也看到了您在我的示例中描述的奇怪之处。我使用此代码得到以下错误:
ValueError:posx和posy应该是有限值
。所有(错误放置)白线的处理方法是什么?
import numpy as np
import pandas as pd
import seaborn as sns
x =  10**np.arange(1, 10)
y = 10** np.arange(1,10)*2
df1 = pd.DataFrame( data=y, index=x )
df2 = pd.DataFrame(data = {'x': x, 'y': y}) 
sns.lmplot('x', 'y', df2)
plt.xscale('log')
plt.yscale('log')