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_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
ax.plot(dateNumList,yList)
效果如下: