Plotting Pandas into subplots

import pandas as pd
import matplotlib.pyplot as plt
data=pd.DataFrame({"col1":[1,2,3,4,5],"col2":[2,4,6,8,10]})
fig=plt.figure()
ax1=fig.add_subplot(2,1,1)
ax2=fig.add_subplot(2,1,2)
data["col1"].plot(ax=ax1)
data["col2"].plot(ax=ax2)

Create a plt.figure() and assign subplots to ax1 and ax2.Now plot the dataframe using these axes.

Reference:-

  1. Pyplot

Leave a Comment