【发布时间】:2020-12-01 10:23:45
【问题描述】:
我已经对 pandas 数据框进行了分组:
DailyTests pos_DailyTests percentOfPositive
Week
44 1079 45 4.00
45 14593 706 4.64
46 18290 1003 5.14
47 19271 1237 6.07
48 12258 938 7.04
我想根据这些数据绘制图表。 “周”是 x 轴,前两列是堆积条形图,第三列应该是折线图。但该行不显示
我的代码:
fig , ax1 = plt.subplots()
ax2 = ax1.twinx()
data_con2.plot(kind='bar', stacked = True, ax=ax1, y = ['DailyTests','pos_DailyTests'])
data_con2.plot(kind='line', ax=ax2, y = 'percentOfPositive', color="red")
ax1.set_ylabel('Tests in day')
ax2.set_ylabel('percent of positives')
示例图如下:
【问题讨论】:
标签: python pandas matplotlib