plotting data with x-axis as date read from matrix, but not all dates appear on the figure

2 次查看(过去 30 天)
the matrix contains dates like:
'4/19/2020' [19]
'4/20/2020' [20]
'4/21/2020' [21]
'4/22/2020' [22]
'4/23/2020' [23]
'4/24/2020' [24]
'4/25/2020' [25]
'4/26/2020' [26]
'4/27/2020' [27]
'4/28/2020' [28]
'4/29/2020' [29]
'4/30/2020' [30]
'5/1/2020' [ 1]
'5/2/2020' [ 2]
'5/3/2020' [ 3]
am trying to plot the data with respect of the date in the matrix, cc contains the values from BBcountry, and the second column of BBcountry contain the dates ordered in ascending order, first row contains the minimum date and the last row contains the maximum one. the figure shows 30-april as max tick in x-axis while the data contains 3-may
i used
plot(datetime(BBcountry(2:end,1)),cc,'DisplayName','alg','Color', 'blue','LineWidth',1),grid on,grid minor;
datetick('x','dd-mmm-yy','keepticks');
xlim([datenum(BBcountry(2,1)) datenum(BBcountry(end,1))])
ax = gca;
ax.XTickLabelRotation = 45;
xticks=get(gca,'xtick');
set(gca,'xticklabel',cellstr(datestr(xticks))')
when i ran it iget :

采纳的回答

abdullah alzaqebah
abdullah alzaqebah 2020-5-22
编辑:abdullah alzaqebah 2020-5-22
solved
i used the following code:
and i get this figure
plot(datetime(BBcountry(2:end,1)),cc,'DisplayName','alg','Color', 'blue','LineWidth',1),grid on,grid minor;
xlim([datenum(BBcountry(2,1)) datenum(BBcountry(end,1))])
DateString = (BBcountry(2:end,1));
datenum(DateString);
set(gca, 'XTick', datenum(DateString))
datetick('x','dd-mmm','keepticks');
ax = gca;
ax.XTickLabelRotation = 90;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

标签

产品


版本

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by