plot pandas series with matplotlib

Solutions on MaxInterview for plot pandas series with matplotlib by the best coders in the world

showing results for - "plot pandas series with matplotlib"
Bennett
12 Nov 2016
1import matplotlib.pyplot as plt
2
3# maximum range of data available for all three metrics = [2006-2010]
4sold = home_data.loc[home_data.YearBuilt >= 2006].groupby(by=["YrSold"]).Id.count()
5built = home_data.loc[home_data.YearBuilt >= 2006].groupby(by=["YearBuilt"]).Id.count()
6modd = home_data.loc[home_data.YearBuilt >= 2006].groupby(by=["YearRemodAdd"]).Id.count()
7
8# extend the data to current year(2021)
9extend_series = pd.Series([0 for i in range(2011,2022)], index=range(2011,2022))
10sold = pd.concat([sold,extend_series])
11built = pd.concat([built,extend_series])
12modd = pd.concat([built,extend_series])
13
14plt.figure(figsize=(10,16))
15
16plt.subplot(311)
17plt.xlabel("Year")
18plt.ylabel("# of Houses Built")
19plt.plot(built.index, built, color='green')
20
21plt.subplot(312)
22plt.xlabel("Year")
23plt.ylabel("# of Houses Sold")
24plt.plot(sold.index, sold, color='red')
25
26plt.subplot(313)
27plt.xlabel("Year")
28plt.ylabel("# of Houses ReModded")
29plt.plot(modd.index, modd, color='cyan')
30