I am trying to plot a 10box plot in one image, in two rows, with the given code but no success, how can I implement this idea.
fig, axes =plt.subplots(2,5)
sns.set_style("darkgrid")
for i,t in enumerate(new_fs):
df = pd.read_csv(t,sep='\t')
sns.boxplot(data=df, orient='v',ax=axes[i % 2] )
Thank you.
As per the documentation for plt.subplots()
:
for NxM, subplots with N>1 and M>1 are returned as a 2D array.
Therefore, your variable axes
is a 2D array, you need to access the individual axes using axes[i,j]
.
Alternatively, I would rewrite your for loop like so:
for t,ax in zip(new_fs, axes.flat):
df = pd.read_csv(t,sep='\t')
sns.boxplot(data=df, orient='v', ax=ax)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.