【发布时间】:2020-05-28 08:11:55
【问题描述】:
您好,我有一些日期,我正在尝试绘制一个历史。我的意思是我有一些日期,我想要一个显示每月频率的历史记录。这是我的代码:
import numpy as np
from datetime import datetime
import matplotlib.pyplot as plt
dateslist = ["25/07/2019", "25/07/2019",
"25/07/2019", "26/07/2019", "29/07/2019",
"29/07/2019", "30/07/2019", "18/08/2019",
"18/08/2019", "20/08/2019", "20/08/2019",
"21/08/2019", "21/08/2019", "22/08/2019",
"27/08/2019", "23/09/2019", "26/09/2019",
"27/09/2019", "30/09/2019", "09/10/2019",
"18/10/2019", "18/10/2019", "18/10/2019",
"18/10/2019", "29/10/2019", "29/10/2019",
"21/11/2019", "21/11/2019", "21/11/2019",
"21/11/2019", "21/11/2019", "21/11/2019",
"21/11/2019", "21/11/2019", "21/11/2019",
"21/11/2019", "29/11/2019", "06/12/2019",
"11/12/2019", "12/12/2019", "18/12/2019",
"23/12/2019", "23/12/2019", "23/12/2019",
"24/12/2019", "24/12/2019", "23/01/2020",
"20/01/2020", "20/01/2020", "20/01/2020",
"19/02/2020", "31/01/2020", "24/02/2020",
"25/02/2020", "25/02/2020", "02/03/2020",
"18/03/2020", "19/03/2020", "23/03/2020",
"02/04/2020", "14/04/2020", "21/04/2020",
"24/04/2020", "20/05/2020"]
dateslistconverted = []
for datelist in dateslist:
if datetime.strptime(datelist, "%d/%m/%Y").month in range(1,6):
dateslistconverted.append(datetime.strptime(datelist, "%d/%m/%Y").month+12)
else:
dateslistconverted.append(datetime.strptime(datelist, "%d/%m/%Y").month)
plt.hist(dateslistconverted)
plt.show()
但我没有合适的格式,我希望日期按时间排序,并在不同月份之间留一些空格。
我该怎么办?
非常感谢!
【问题讨论】:
标签: python python-3.x matplotlib histogram