Plot specific column values in Seaborn instead of every column value

Viewed 2992

I can't figure out how to filter a column and then plot it successfully on Seaborn.

The below code works perfectly and plots a line graph with all of the unique columns values separated.

import geopandas as gpd
import matplotlib.pyplot as plt 
import pandas as pd 
import numpy as np
import seaborn as sns

sns.set(style='darkgrid')
data = wcsales1.loc[wcsales1.Sales_Year > 2016]
sales_year = data['Sales_Year']
ppa = data['Price_Per_Acre']
dates = data['LATEST_LAND_SALE_DATE']
juris = data['PLANNING_JURISDICTION']

sns.relplot(x = sales_year, y = ppa, ci=None, kind='line', hue=juris)
plt.show()

However, I want to plot the values in the variable 'egs', listed below, which are two of many unique values in the variable 'juris'

I tried the below code but am getting a Value Error, also included below.

import geopandas as gpd
import matplotlib.pyplot as plt 
import pandas as pd 
import numpy as np
import seaborn as sns

sns.set(style='darkgrid')
data = wcsales1.loc[wcsales1.Sales_Year > 2016]
data = data.reset_index()
sales_year = data['Sales_Year']
ppa = data['Price_Per_Acre']
dates = data['LATEST_LAND_SALE_DATE']
juris = data['PLANNING_JURISDICTION']
egs = ['HS', 'FV']
south = data.loc[data.PLANNING_JURISDICTION.isin(egs)]
print(type(south))

sns.relplot(x = sales_year, y = ppa, ci=None, kind='line', hue=south)
plt.show()

Error below

Shape of passed values is (19, 3), indices imply (1685, 3)

Thanks for your help!

1 Answers

With sns you should pass the data option and x,y, hue as the columns in the data:

sns.relplot(x='Sales_Year', y='Price_Per_Acre',
            hue='PLANNING_JURISDICTION',
            data=data.loc[data.PLANNING_JURISDICTION.isin(egs)],
            kind='line', ci=None
           )

           
Related