Matplotlib 日期格式转换
官网链接:https://matplotlib.org/api/dates_api.html#matplotlib.dates.date2num
import numpy as np import datetime import matplotlib as pl from matplotlib.dates import date2num, num2date #datetime 格式 dt=datetime.datetime(2001,1,2,10,10,59) #numpy datetime64 格式 dt64 = np.datetime64(dt) #date 转num 这里也可接受datetime格式,dt64改为dt n =date2num(dt64) print(n) #num 转Matplolib date num=[731385,] date = num2date(num[0]).strftime('%Y/%m/%d %H:%M:%S') print(date)
结果:
======= RESTART: C:\Users\Administrator\Desktop\matplotlib date .py =======
730487.4242939815
2003/06/19 00:00:00
>>>