Home > Net >  How to combine boxplot figures into one?
How to combine boxplot figures into one?

Time:10-17

I am working now on plot my dataset by boxplot as in below code

plt.figure(figsize=(8,5))
fig = plt.figure()
num_list=Final_dataset.columns.values.tolist()
for i in range(len(num_list)):
    column=num_list[i]
    sns.boxplot(x="label", y=column, data=Final_dataset, palette='Set2')
    plt.savefig('{}.png'. format(i))
    plt.show()

I need to produce one image that combine all attributes figures as in this figure rather than several figures. how Ican fix it? thanks, a lot

CodePudding user response:

See subplot function in matplotlib.

nrows = 3 # decide how many you want
ncols = 4 # decide how many you want
plt.figure(figsize=(8,5))
num_list=Final_dataset.columns.values.tolist()
for i in range(len(num_list)):
    column=num_list[i]
    sns.boxplot(x="label", y=column, data=Final_dataset, palette='Set2')
    plt.subplot(nrows, ncols, index = 1 i)
plt.savefig('{}.png'. format(i))
plt.show()

  • Related