Python 使用matplotlib精简日期格式绘制时间序列图像
import datetime
from matplotlib import dates
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
dateList=['2022-01-01','2022-01-02','2022-01-04','2022-01-05','2022-01-08','2022-01-11']
yList=[1,3,4,6,5,8]
dateNumList=[dates.date2num(datetime.datetime.strptime(x,'%Y-%m-%d')) for x in dateList] #转换为数字格式
fig,ax=plt.subplots()
locator=mdates.AutoDateLocator(minticks=3,maxticks=7) #括号内的两个参数可以调正刻度的数量
formatter=mdates.ConciseDateFormatter(locator)
ax.xaxis.set_
共有 0 条评论