You can build multiple subplots of several pandas data frames using matplotlib, with a simple trick of listing all the data frames. Then use the for loop to build the subplots.
Work code:
import matplotlib.pyplot as plt import pandas as pd import numpy as np # dataframe sample data df1 = pd.DataFrame(np.random.rand(10,2)*100, columns=['A', 'B']) df2 = pd.DataFrame(np.random.rand(10,2)*100, columns=['A', 'B']) df3 = pd.DataFrame(np.random.rand(10,2)*100, columns=['A', 'B']) df4 = pd.DataFrame(np.random.rand(10,2)*100, columns=['A', 'B']) df5 = pd.DataFrame(np.random.rand(10,2)*100, columns=['A', 'B']) df6 = pd.DataFrame(np.random.rand(10,2)*100, columns=['A', 'B']) #define number of rows and columns for subplots nrow=3 ncol=2 # make a list of all dataframes df_list = [df1 ,df2, df3, df4, df5, df6] fig, axes = plt.subplots(nrow, ncol) # plot counter count=0 for r in range(nrow): for c in range(ncol): df_list[count].plot(ax=axes[r,c]) count=+1

Using this code, you can build subplots in any configuration. You just need to determine the number of nrow rows and the number of ncol columns. You also need to make a list of the df_list data df_list that you want to build.
Arslan Ahmad Jun 23 '19 at 13:26 2019-06-23 13:26
source share