Answers for "plot pandas series with matplotlib"

0

plot pandas series with matplotlib

import matplotlib.pyplot as plt

# maximum range of data available for all three metrics = [2006-2010]
sold = home_data.loc[home_data.YearBuilt >= 2006].groupby(by=["YrSold"]).Id.count()
built = home_data.loc[home_data.YearBuilt >= 2006].groupby(by=["YearBuilt"]).Id.count()
modd = home_data.loc[home_data.YearBuilt >= 2006].groupby(by=["YearRemodAdd"]).Id.count()

# extend the data to current year(2021)
extend_series = pd.Series([0 for i in range(2011,2022)], index=range(2011,2022))
sold = pd.concat([sold,extend_series])
built = pd.concat([built,extend_series])
modd = pd.concat([built,extend_series])

plt.figure(figsize=(10,16))

plt.subplot(311)
plt.xlabel("Year")
plt.ylabel("# of Houses Built")
plt.plot(built.index, built, color='green')

plt.subplot(312)
plt.xlabel("Year")
plt.ylabel("# of Houses Sold")
plt.plot(sold.index, sold, color='red')

plt.subplot(313)
plt.xlabel("Year")
plt.ylabel("# of Houses ReModded")
plt.plot(modd.index, modd, color='cyan')
Posted by: Guest on August-28-2021

Python Answers by Framework

Browse Popular Code Answers by Language