pythonseaborntypeerrorkeyword-argumentpositional-argument

How to Pass Seaborn Positional and Keyword Arguments


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.

Solution

  • Seaborn >= 0.12


    Seaborn 0.11

    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)
    

    enter image description here

    # 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')
    

    enter image description here

    Ignore the warnings

    import warnings
    warnings.simplefilter(action="ignore", category=FutureWarning)
    
    # plot without specifying the x, y parameters
    sns.regplot(x, y)
    

    enter image description here