Plotting date (number) on x-axis

5 visualizaciones (últimos 30 días)
Gligor Terziev
Gligor Terziev el 18 de Abr. de 2021
Comentada: Star Strider el 19 de Abr. de 2021
I want to plot all the day numbers on x-axis. I have really big timeseries data with 10-min wind speed averages, starting from 1st April and ending 30th April. I want to plot the wind speed, measured every 10min during the day, for the whole month. And on the x-axis I want to have ticks for every day starting from 1 till 30. Here is the code:
%% direct timetable importing
clc
clear
load april.mat %april timetable
dnum = day(ex1.timestamp);
mnum = month(ex1.timestamp);
myear = year(ex1.timestamp);
myear = unique(myear); %finding year
mnum = unique(mnum); %fingind month number
dlast = unique(max(dnum)); %finding last day
duniq = unique(dnum);
duniq = num2cell(duniq);
plot(ex1.timestamp,ex1.CH1Avg)
hAx = gca;
xlim(datetime([myear myear],[mnum mnum],[1 dlast])); %setting limits
xticklabels(duniq); %setting ticks to 30 like the number of days in April
datetick('x','dd'); %using date ticks, not working when trying dd
When i use in datetick('x','d') it is working. But when i use datetick('x' ,'dd') -it is not working. I also tried with datetick('x','d','keepticks'), but not working properly.
Can someone please help me?
Like it is shown on screenshot I want on x axis to have evenly distributed ticks for every day, starting from 01,02... ending at 30. like it is set in xlim

Respuesta aceptada

Star Strider
Star Strider el 18 de Abr. de 2021
It is necessary to be creative with the plot and the tick labels.
Try this:
DL = load('april.mat');
ex1 = DL.ex1;
Q1 = ex1(1:10,:);
monthinfo = ex1.timestamp(1);
daylim = eomday(year(monthinfo),month(monthinfo));
figure
plot((1:size(ex1,1)),ex1.CH1Avg)
xt = get(gca,'XTick');
set(gca,'XTick',linspace(min(xt),max(xt),daylim), 'XTickLabel',compose('%02d',(1:daylim)))
Experiment to get the result you want.
  4 comentarios
Gligor Terziev
Gligor Terziev el 19 de Abr. de 2021
Thanks a lot.
Star Strider
Star Strider el 19 de Abr. de 2021
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by