gpt4 book ai didi

python - 使用 seaborn 对数对数 lmplot

转载 作者:IT老高 更新时间:2023-10-28 22:21:31 25 4
gpt4 key购买 nike

Seaborn 中的函数 lmplot 可以在对数刻度上绘制吗?这是正常比例的 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)

sns.lmplot('x', 'y', df2)

最佳答案

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

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

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

f, ax = plt.subplots(figsize=(7, 7))
ax.set(xscale="log", yscale="log")
sns.regplot("x", "y", data, ax=ax, scatter_kws={"s": 100})

enter image description here

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

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

enter image description here

关于python - 使用 seaborn 对数对数 lmplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23913151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com