【发布时间】:2017-07-01 14:19:11
【问题描述】:
我想充分利用this 和this 的问题。也就是说,我有一个DataFrame,其中包含测试名称、执行日期和结果。我想展示失败案例的百分比如何随着时间的推移而下降。
我的数据如下所示:
TestName;Date;IsPassed
test1;12/8/2016 9:44:30 PM;0
test1;12/8/2016 9:39:00 PM;0
test1;12/8/2016 9:38:29 PM;1
test1;12/8/2016 9:38:27 PM;1
test2;12/8/2016 5:05:02 AM;1
test3;12/7/2016 8:58:36 PM;0
test3;12/7/2016 8:57:19 PM;1
test3;12/7/2016 8:56:15 PM;1
test4;12/5/2016 6:50:49 PM;0
test4;12/5/2016 6:49:50 PM;0
test4;12/5/2016 3:23:09 AM;1
test4;12/4/2016 11:51:29 PM;1
我正在使用此代码分别绘制案例:
fig, ax = plt.subplots()
passed = tests[tests.IsPassed == 1]
failed = tests[tests.IsPassed == 0]
passed_dates = mdates.date2num(passed.Date.astype(datetime))
failed_dates = mdates.date2num(failed.Date.astype(datetime))
ax.hist(passed_dates, bins=10, color='g')
ax.hist(failed_dates, bins=10, color='r')
ax.xaxis.set_major_locator(mdates.AutoDateLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter('%d.%m.%y'))
plt.show()
但现在我想
- 将时间跨度划分为可配置数量的存储桶
- 计算每个存储桶的测试运行次数(没有 for 循环,因为数据框中有很多条目)
- 绘制 100% 面积图或每个桶的堆积直方图,以便步骤 2 的数量为 100%
我现在的问题是hist() 的完美工作解决方案会自动汇总,我看不到将 Y 轴传递给它的方法。
更新
【问题讨论】:
标签: python matplotlib plot time histogram