使用 seaborn 对数记录 lmplot [英] Log-log lmplot with seaborn

查看:56
本文介绍了使用 seaborn 对数记录 lmplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Seaborn 中的函数 lmplot 可以在对数尺度上绘制吗?这是正常比例的lmplot

Can the function lmplot from Seaborn plot on a log-log scale? This is lmplot on a normal scale

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.regplot 会更容易.这似乎有效(虽然我不确定 y 轴小网格的位置)

If you just want to plot a simple regression, it will be easier to use seaborn.regplot. This seems to work (although I'm not sure where the y axis minor grid goes)

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

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

If you need to use lmplot for other purposes, this is what comes to mind, but I'm not sure what's happening with the x axis ticks. If someone has ideas and it's a bug in seaborn, I'm happy to fix it:

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

这篇关于使用 seaborn 对数记录 lmplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆