seaborn FutureWarning:将以下变量作为关键字参数传递:x, y [英] seaborn FutureWarning: Pass the following variables as keyword args: x, y
本文介绍了seaborn FutureWarning:将以下变量作为关键字参数传递:x, y的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想绘制一个seaborn regplot.我的代码:
x=data['健康预期寿命']y=data['max_dead']sns.regplot(x,y)plt.show()
然而,这给了我未来的警告错误.如何修复此警告?
FutureWarning:将以下变量作为关键字参数传递:x、y.从 0.12 版开始,唯一有效的位置参数将是数据",并且在没有显式关键字的情况下传递其他参数将导致错误或误解.
解决方案
- 从技术上讲,这是一个警告,而不是错误,现在可以忽略,如本答案底部所示.
- 我建议按照警告的说明进行操作,为
# 指定 x, y 参数的绘图sns.regplot(x=x, y=y)# 或使用sns.regplot(data=pen, x='bill_depth_mm', y='bill_length_mm')
忽略警告
- 我不建议使用此选项.
- 一旦 seaborn v0.12 可用,此选项将不可行.
- 从 0.12 版本开始,唯一有效的位置参数将是
data
,并且在没有显式关键字的情况下传递其他参数将导致错误或误解.
导入警告warnings.simplefilter(action=ignore", category=FutureWarning)# 不指定 x, y 参数的绘图sns.regplot(x, y)
I want to plot a seaborn regplot. my code:
x=data['Healthy life expectancy'] y=data['max_dead'] sns.regplot(x,y) plt.show()
However this gives me future warning error. How to fix this warning?
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.
解决方案- Technically, it's a warning, not an error, and can be ignored for now, as shown in the bottom section of this answer.
- I recommend doing as the warning says, specify the
x
andy
parameters forseaborn.regplot
, or any of the other seaborn plot functions with this warning. sns.regplot(x=x, y=y)
, wherex
andy
are parameters forregplot
, to which you are passingx
andy
variables.- Beginning in version 0.12, passing any positional arguments, except
data
, will result in anerror
ormisinterpretation
.- For those concerned with backward compatibility, write a script to fix existing code, or don't update to 0.12 (once available).
x
andy
are used as the data variable names because that is what is used in the OP. Data can be assigned to any variable name (e.g.a
andb
).- This also applies to
FutureWarning: Pass the following variable as a keyword arg: x
, which can be generated by plots only requiringx
ory
, such as:sns.countplot(pen['sex'])
, but should besns.countplot(x=pen['sex'])
orsns.countplot(y=pen['sex'])
import seaborn as sns import pandas as pd pen = sns.load_dataset('penguins') x = pen.culmen_depth_mm # or bill_depth_mm y = pen.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=pen, x='bill_depth_mm', y='bill_length_mm')
Ignore the warnings
- I do not advise using this option.
- Once seaborn v0.12 is available, this option will not be viable.
- 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.
import warnings warnings.simplefilter(action="ignore", category=FutureWarning) # plot without specifying the x, y parameters sns.regplot(x, y)
这篇关于seaborn FutureWarning:将以下变量作为关键字参数传递:x, y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文