Search code examples
pythonpandasmatplotlibsubplot

How to plot different dataframe in my code on each iteration?


I want my figures in a particular layout, This is the code to plot that

fig, axes = plt.subplots(figsize=(10, 10), ncols=2, nrows=4)
for i in range(4):
    for j in range(2):
        if i<j:
            axes[i, j].axis('off')
        else:
            print(i,j)
            axes[i, j].hist(df1.col1,bins=20,edgecolor='k')

But I want to plot different datasets (df1.col1,df2.col1,...df7.col1) in each subplot (Total 7 dataset).

What modifications I should do to plot that using this code??


Solution

  • You could try the list,

    a=[df1,df2,df3,df4,df5,df6,df7]
    k=0
    fig, axes = plt.subplots(figsize=(10, 10), ncols=2, nrows=4)
    for i in range(4):
        for j in range(2):
            if i<j:
                axes[i, j].axis('off')
            else:
                print(i,j)
                # axes[i, j].hist(set_SS.depth,bins=20,edgecolor='k')
                
                axes[i, j].hist(a[k].col1,bins=20,edgecolor='k')
                k+=1