How to label dates on X-axis as string on monthly time step?
4 次查看(过去 30 天)
显示 更早的评论
Hello, I would like to see dates on axis as a string in a month-year format with jumping steps for figure enhancement. Here is my code so far but when I tried to execute it, it generates year1 with steps 1,2 3 (see the plot).
Date=unique(cellstr(datestr((datenum('1981-01-01', 'yyyy-mm-dd'):datenum('2010-12-31', 'yyyy-mm-dd'))', 'yyyy-mm')));
figure();
hold on
fill([(1:360) fliplr(1:360)],[Gauge4(:,3)' fliplr(Gauge4(:,2)')],'c','FaceColor',[0.83 0.82 0.78],'EdgeColor',[0.83 0.82 0.78]);
plot(Gauge4(:,1),'-r','LineWidth',1.25);
plot(Gauge4(:,4),'--b','LineWidth',1.25);
axis tight
set(gca,'XTick',1:36:360,'XTickLabel',Date);
0 个评论
回答(2 个)
KL
2017-11-1
You already have year and month on the xaxis of the attached image but anyway, you could directly plot with the datetime on xaxis,
plot(Date,guage(:,3))
datetick('x','yyyy-mm')
Nurhaida Nurhaida
2019-11-1
Hi..KL..try this
set(gca,'XTick',1:36:360,'XTickLabel',Date(1:36:360));
Nur
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!