Specify specific Interval between datetime values on x axis of plot

Hi All,
I am plotting some time series data. Where the times are specified in datetime format starting '01-Oct-2021' and ending '28-Feb-2023 23:54:59'. I would like to plot the data with specific labels on the x axis. The code I have at the moment is as follows:
plot(Time,Watts3Ph/1000,'color','r')
grid on
ylim([0 65]);
yticks([0:5:65]);
xlim([Time(1) Time(end)])
datetick('x','dd/mm/yy HH:MM','keeplimits','keepticks')
ax.FontSize = 16;
xlabel('Time','FontSize',20)
ylabel('Load Demand (kW)','FontSize',20)
title('Load Demand','FontSize',22)
legend('Heading','FontSize',16)
legend('Location','northeastoutside')
What I want to do is specfy x labels at '01-Oct-2021', '30-Nov-2021 23:59:59','28-Feb-2022 23:59:59','31-May-2022 23:59:59','31-Aug-2022 23:59:59', '30-Nov-2022 23:59:59','28-Feb-2023 23:54:59'
I would also like to add verticle dashed lines at each of those x axis dates. Is this possible???
Thanks

 Respuesta aceptada

Cris LaPierre
Cris LaPierre el 18 de Mzo. de 2023
Editada: Cris LaPierre el 18 de Mzo. de 2023
Use the xticks funtion to specify where to place the ticks.
Use xline with the same x values to add a vertical line at each location. You can specify the linestyle.
If your X values are already datetimes, you don't need to use dateticks. Instead, you would set the format using xtickformat.

Más respuestas (0)

Categorías

Más información sobre Axes Appearance en Centro de ayuda y File Exchange.

Productos

Versión

R2022b

Preguntada:

el 17 de Mzo. de 2023

Editada:

el 18 de Mzo. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by