1

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

1
  • Nope, Its for the subplot layout convenience Commented Dec 6, 2021 at 6:28

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.