Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

python - seaborn FutureWarning: Pass the following variables as keyword args: 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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  • I recommend doing as the warning says, specify the x and y parameters for seaborn.regplot, or any of the other seaborn plot functions with this warning.
  • sns.regplot(x=x, y=y), where x and y are parameters for regplot, to which you are passing x and y variables.
  • Beginning in version 0.12, passing any positional arguments, except data, will result in an error or misinterpretation.
  • x and y 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 and b).
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)

enter image description here

# plot with specifying the x, y parameters
sns.regplot(x=x, y=y)

enter image description here

Ignore the warnings

  • I do not advise using this option.
  • Once seaborn v0.12 is available, this option may 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)

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...