您是否考虑过与实际工作日期格式?这样你的时间参数就可以按时间顺序排列。
首先做一些准备工作:
days = [22 23 24 25 26 27 28 29 30 31 1 2 3 4];
months = [1 1 1 1 1 1 1 1 1 1 2 2 2 2];
year = repmat(2015,numel(days),1);
in_bed = [3 8 26 76 225 298 258 233 189 128 68 29 14 4];
convalescent = [0 0 0 0 9 17 105 162 176 166 150 85 47 20];
创建一个datevec(日期向量)
dateVector = [year(:) months(:) days(:)];
并将其转换为双精度值datenum:
date = datenum(dateVector);
绘制并修复 x 刻度
plot(date,in_bed,'*',date,convalescent,'*')
set(gca,'XTick',date) %// if you leave this step, labeling is dynamic!
定义标签的格式datetick:
datetick('x','dd-mm','keepticks')
and voilà:
![enter image description here](https://i.stack.imgur.com/D3qn3.png)