使用子图从数据框中绘制条形图

Elv*_*ang 1 matplotlib pandas

我有一个熊猫数据框。我想使用 subplot 来绘制两条曲线。但是,我下面的代码在子图中不返回条形图

fig, axes = plt.subplots(2,1, figsize=(10,10))
axes[0] = recent_grads[:5].plot.bar(x='Major', y='Income')
axes[1] = recent_grads[167:172].plot.bar(x='Major', y='Income')
plt.show()
Run Code Online (Sandbox Code Playgroud)

Dav*_*idG 5

您需要使用以下方法将子图作为参数传递给绘图函数ax=

fig, axes = plt.subplots(2,1, figsize=(10,10))
recent_grads[:5].plot.bar(x='Major', y='Income', ax=axes[0])
recent_grads[167:172].plot.bar(x='Major', y='Income', ax=axes[1)
plt.show()
Run Code Online (Sandbox Code Playgroud)