【发布时间】:2021-02-06 00:07:54
【问题描述】:
我正在尝试并排绘制两个连续变量的 BAR PLOT。没有成功。
df_cooking= df.groupby(df['region'])['cook_time','prep_time'].mean().reset_index()
df_cooking.head(6)
region cook_time prep_time
0 Central 48.333333 13.333333
1 East 41.607143 43.518519
2 North 41.979167 38.020833
3 North East 28.461538 28.846154
4 South 36.909091 58.181818
5 West 41.880597 16.924242
这就是我使用 seaborn 尝试过的方式:
plt.figure(figsize=(8,9))
plt.bar(df_cooking['region'],df_cooking['prep_time'], label = 'Preparation Time', color= 'c')
plt.bar(df_cooking['region'],df_cooking['cook_time'], label = 'Cooking Time', color = 'r')
plt.xlabel('Region')
plt.ylabel('Time in Minutes')
plt.title('Cooking and Preparation Time per Region')
plt.legend()
plt.show()
提前感谢您的帮助!
【问题讨论】:
标签: python-3.x pandas seaborn data-science