How do I control the format of the date stamp on a plot axis with datetime values?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I have some data with timestamps, so I have plotted values on the y-axis versus a datetime array on the x-axis.
I really like that Matlab summarized the date for me, since all the ticks have the date in common, only a different time. Similarly, it will summarize the year if all ticks have this in common. However, how do I control the format of this extra label on the axis, in this case the date? I can control the format of the xticks, but that is not what I'm looking for. I would like to display the date differently (eg 'd MMMM yyyy'), instead of the 'MMMM d, yyyy' that it is now.
0 Kommentare
Akzeptierte Antwort
Stephen23
am 13 Feb. 2024
Bearbeitet: Stephen23
am 13 Feb. 2024
That is named the secondary label and has some rather rudimentary controls, e.g.:
Unfortunately to control its format you will need to dig into some undocumented features... and (AFAIK) we will have to modify the text after the plot command. Lets try now:
X = datetime(2024,2,13,0:23,0,0);
Y = rand(1,numel(X));
plot(X,Y)
A = gca;
drawnow() % the forum requires this
S = A.XRuler.SecondaryLabel.String
D = datetime(S, 'InputFormat','MMM d, y', 'Format','d MMMM yyyy')
A.XRuler.SecondaryLabel.String = char(D);
hold on
plot(0,0) % required to update the forum plot
See also:
Tip: go to the xSecondaryLabel page (linked at the top of my answer), scroll to the very bottom, give a rating (of your choice) together with the feedback that the function needs to include the ability to change the date format.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!