2

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!

2
  • please show the plots that you have done Commented Nov 25, 2020 at 21:08
  • filter the data set based on your required columns data[(data.column==value1) & (data.column==value2)] Commented Nov 25, 2020 at 21:10

1 Answer 1

2

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
           )

           
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.