from datetime import datetime import matplotlib.dates as mdates import matplotlib.pyplot as plt # 生成横纵坐标信息 dates = ['2016-12-20 09:52:54', '2016-12-20 15:52:54', '2016-12-20 21:52:54', '2016-12-21 03:52:54'] xs = [datetime.strptime(m,'%Y-%m-%d %H:%M:%S').date() for m in dates] ys = range(len(xs)) print(xs) print(ys) # 配置横坐标 plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d')) plt.gca().xaxis.set_major_locator(mdates.DayLocator()) # Plot plt.plot(xs, ys) plt.gcf().autofmt_xdate() # 自动旋转日期标记 plt.show()
matplotlib.dates 年月日 小时分,画图
最新推荐文章于 2025-02-20 20:51:29 发布