0

I want to plot two subplot in in one plot using matplotlib

my code is as following:

fig, axes = plt.subplots(ncols=2)

df5.plot(ax=axes[0], kind='bar' ,stacked=True)
ax[0,0].set_title("metagenome data")
plt.xticks(r1, names1)
plt.xlabel("Sample")
plt.legend(loc='upper left', bbox_to_anchor=(1,1), ncol=1)

df_b5.plot(ax=axes[1], kind='bar', stacked=True)
ax[0,1].set_title("Amplicon data")
plt.xticks(r2, names2)
plt.xlabel("Sample") 
plt.legend(loc='upper left', bbox_to_anchor=(1,1), ncol=1) 

and only the first one is at the plot what am I doing wrong?

any help will be grate! TNX!

Rotem Bartuv
  • 133
  • 7
  • Did you check whether you got an error? Python stops at such error and might show the partial plot up till the line with the error. Default `plt.plots(...)` returns a 1D array of axes (when you call it as `plt.plots(..., squeeze=False)` it always returns a 2D array of axes). So you might need to use `ax[0].set_title(...)` and `ax[1].set_title(...)`. – JohanC Aug 11 '20 at 12:17
  • Where do you define `ax`? – Ynjxsjmh Aug 11 '20 at 13:08
  • 1
    Does this answer your question? [How do I get multiple subplots in matplotlib?](https://stackoverflow.com/questions/31726643/how-do-i-get-multiple-subplots-in-matplotlib) – Trenton McKinney Aug 11 '20 at 17:57

0 Answers0