Answers for "plot pandas dataframe matplotlib"

11

plot a pandas dataframe matplotlib

import pandas as pd
import matplotlib.pyplot as plt
df = pd.Dataframe(Data)
df.plot(kind='bar',x="dataframe_1",y="dataframe_2") # bar can be replaced by 
# scatter or line or even left as default
plt.show()
Posted by: Guest on March-19-2021
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

Code answers related to "plot pandas dataframe matplotlib"

Python Answers by Framework

Browse Popular Code Answers by Language