seaborn FutureWarning:将以下变量作为关键字参数传递:x, y

che*_*rry 8 python plot seaborn

我想绘制一个seaborn regplot。我的代码:

x=data['Healthy life expectancy']
y=data['max_dead']
sns.regplot(x,y)
plt.show()
Run Code Online (Sandbox Code Playgroud)

然而,这给了我未来的警告错误。如何修复此警告?

FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid 
positional argument will be 'data', and passing other arguments without an explicit keyword will 
result in an error or misinterpretation.
Run Code Online (Sandbox Code Playgroud)

Tre*_*ney 17

  • 我建议按照警告的说明进行操作,为或任何其他带有此警告的 seaborn 绘图函数指定xy参数seaborn.regplot
  • sns.regplot(x=x, y=y), wherexyregplot, 传递给的参数xy变量。
  • 从 0.12 版开始,传递任何位置参数,除了data,将导致errormisinterpretation
  • xy用作数据变量名称,因为这是 OP 中使用的名称。数据可以分配给任何变量名(例如ab)。
import seaborn as sns
import pandas as pd

pen = sns.load_dataset('penguins')

x = pen.culmen_depth_mm
y = pen.culmen_length_mm

# plot without specifying the x, y parameters
sns.regplot(x, y)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

# plot with specifying the x, y parameters
sns.regplot(x=x, y=y)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

忽略警告

  • 我不建议使用此选项。
  • 一旦 seaborn v0.12 可用,此选项可能不可行。
  • 从 0.12 版开始,唯一有效的位置参数将是data,并且在没有显式关键字的情况下传递其他参数将导致错误或误解。
import warnings
warnings.simplefilter(action="ignore", category=FutureWarning)

# plot without specifying the x, y parameters
sns.regplot(x, y)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明