我想绘制一个seaborn regplot。 我的代码:
x=data['Healthy life expectancy']
y=data['max_dead']
sns.regplot(x,y)
plt.show()
但是这给了我未来的警告错误。如何解决这个警告?
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.
seaborn 0.12
,FutureWarning
中的 seaborn 0.11
现在是 TypeError
。data
指定为seaborn图的第一个位置参数。所有其他参数必须使用关键字(例如 x=
和 y=
)。 这适用于所有 seaborn
绘图函数。
sns.*plot(data=penguins, x="bill_length_mm", y="bill_depth_mm")
或 sns.*plot(penguins, x="bill_length_mm", y="bill_depth_mm")
sns.*plot(data=penguins.bill_length_mm)
或 sns.*plot(penguins.bill_length_mm)
TypeError: *plot() takes from 0 to 1 positional arguments but 3 were given
。
sns.*plot(penguins, "bill_length_mm", "bill_depth_mm")
TypeError: *plot() got multiple values for argument 'data'
和
data=
作为位置参数传递后使用
x
时,会发生
y
。
sns.*plot("bill_length_mm", "bill_depth_mm", data=penguins)
TypeError: *plot() takes from 0 to 1 positional arguments but 2 positional arguments (and 1 keyword-only argument) were given
和
x
传递位置参数,后跟除
y
之外的关键字参数时,会出现
data
sns.*plot(penguins.bill_length_mm, penguins.bill_depth_mm, kind="reg")
python
解释。x
、或任何其他 seaborn 绘图函数指定
y
和 seaborn.regplot
参数。sns.regplot(x=x, y=y)
,其中 x
和 y
是 regplot
的参数,您要向其传递 x
和 y
变量。data
除外)将导致 error
或 misinterpretation
。
x
和 y
用作数据变量名称,因为这是 OP 中使用的名称。数据可以分配给任何变量名称(例如 a
和 b
)。FutureWarning: Pass the following variable as a keyword arg: x
,它可以通过仅需要 x
或 y
的绘图生成,例如:
sns.countplot(penguins['sex'])
,但应该是 sns.countplot(x=penguins['sex'])
或 sns.countplot(y=penguins['sex'])
import seaborn as sns
import pandas as pd
penguins = sns.load_dataset('penguins')
x = penguins.culmen_depth_mm # or bill_depth_mm
y = penguins.culmen_length_mm # or bill_length_mm
# plot without specifying the x, y parameters
sns.regplot(x, y)
# plot with specifying the x, y parameters
sns.regplot(x=x, y=y)
# or use
sns.regplot(data=penguins, x='bill_depth_mm', y='bill_length_mm')
data
,在没有显式关键字的情况下传递其他参数将导致错误或误解。import warnings
warnings.simplefilter(action="ignore", category=FutureWarning)
# plot without specifying the x, y parameters
sns.regplot(x, y)