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
Solution 1:
- 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
xandyparameters forseaborn.regplot, or any of the other seaborn plot functions with this warning. sns.regplot(x=x, y=y), wherexandyare parameters forregplot, to which you are passingxandyvariables.- Beginning in version 0.12, passing any positional arguments, except
data, will result in anerrorormisinterpretation.- For those concerned with backward compatibility, write a script to fix existing code, or don't update to 0.12 (once available).
xandyare 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.aandb).- This also applies to
FutureWarning: Pass the following variable as a keyword arg: x, which can be generated by plots only requiringxory, 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)



Post a Comment for "Seaborn Futurewarning: Pass The Following Variables As Keyword Args: X, Y"