我想把2个matplotlib的图并排放在一起,但每个图都是由groupby函数产生的(见下面的代码,只显示第二个图)。我知道以前也有人问过类似的问题,但都不是和这个问题一模一样。我很感激任何帮助。
ax = df_train.groupby(['Role','Side'])['Result'].mean().plot(kind='bar', figsize=(5,6), fontsize=13)
ax.set_ylabel('Win Rate')
ax.set_title('Win Rate by Role and Side')
ax1 = df_train.groupby(['Role','Side'])['Result'].count().plot(kind='bar', figsize=(5,6), fontsize=13)
ax1.set_ylabel('# of games')
ax1.set_title('# of games by Role and Side')
plt.show()
正如解释在 其他答案这就是你需要做的。
fig, (ax1, ax2) = plt.subplots(1,2, figsize=(10,6))
df_train.groupby(['Role','Side'])['Result'].mean().plot(kind='bar', ax=ax1, fontsize=13)
ax1.set_ylabel('Win Rate')
ax1.set_title('Win Rate by Role and Side')
df_train.groupby(['Role','Side'])['Result'].count().plot(kind='bar', ax=ax2, fontsize=13)
ax2.set_ylabel('# of games')
ax2.set_title('# of games by Role and Side')
plt.show()