1
我想充分利用this和this問題。也就是說,我有一個DataFrame
,其中包含測試名稱,執行日期和結果。我想展示失敗案例的百分比隨着時間的推移而下降。matplotlib中的100%堆積面積/直方圖,日期在X軸上
我的數據是這樣的:
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()
但現在我想
- 鴻溝時間間隔分配到可配置數量的桶中
- 計算t est每桶運行(不包含循環,因爲數據框中有很多條目)
- 繪製100%面積圖或每個桶的堆疊直方圖,以使步驟2中的數量爲100%
對我來說現在的問題是,隨着hist()
的完美工作液照顧總結的自動,我不明白的方式,以Y軸傳遞給它。
更新
不錯!感謝提示。現在有辦法從Y軸的絕對計數切換到百分比嗎?現在有些垃圾箱總計超過一千次,而另一些垃圾箱則少於100 ... –
查看編輯答案。如果這仍然沒有幫助,請隨時進一步詢問。 – ImportanceOfBeingErnest
這正是我一直在尋找的!謝謝,@ImportanceOfBeingErnest!有幾件事情想要改變以適應我的需求,但這些都不是這個問題的主題。 –