Home > front end >  How to plot different dataframe in my code on each iteration?
How to plot different dataframe in my code on each iteration?

Time:12-06

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??

CodePudding user response:

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

CodePudding user response:

You can probably create an array of these columns like

data_frames = [df1.col1, df2.col1, df3.col1, df4.col1, df5.col1, df6.col1, df7.col1]

and then index into this array like:

axes[i, j].hist(dataframes[i*2 j], bins=20, edgecolor='k')
  • Related