Where is the month, day and year string stored in a plot with a datetime axis which shows hours and minutes in the xticklabel string?
Mostra commenti meno recenti
A somewhat specific question which I cannot find the answer for.
Suppose I have some random data measured at different times which I want to plot:
t1 = datetime('2023-04-01 04:00:00');
t2 = datetime('2023-04-01 12:00:00');
t = t1:seconds:t2;
data = rand(length(t),1);
plot(t,data,'.');
ax = gca;
This results in the following plot:

As you can see, this plot results in x tick labels as strings with hours and minutes. But in the bottom right hand corner of the plot, there is also an additional string showing the month, day and year.
Question: Where is this string stored and can it be edited?
I can't find it anywhere in the ax structure variable. The ax.XTickLabel only contains strings with hours and minutes:
>> ax.XTickLabel
ans =
9×1 cell array
{'04:00'}
{'05:00'}
{'06:00'}
{'07:00'}
{'08:00'}
{'09:00'}
{'10:00'}
{'11:00'}
{'12:00'}
I want to edit and customize this string, change its format, (or perhaps get rid of it entirely).
Any help is appreciated.
4 Commenti
Dyuman Joshi
il 17 Gen 2024
Spostato: Dyuman Joshi
il 12 Feb 2024
The data is stored as the x-tick values.
They can be edited, but not all properties can be changed.
t1 = datetime('2023-04-01 04:00:00');
%I've changed the time
t2 = datetime('2023-04-01 05:00:00');
t = t1:seconds:t2;
data = rand(length(t),1);
plot(t,data,'.');
ax = gca;
%Get the data
xt = ax.XTick
%See the format of the data
xt.Format
%To get rid of them, just assign the x ticks to be empty
ax.XTick = [];
You can specify the format with the plot call as well -
figure
plot(t,data,'.',"DatetimeTickFormat","MMM dd, u, HH:mm:ss")
Dyuman Joshi
il 22 Gen 2024
Spostato: Dyuman Joshi
il 12 Feb 2024
Darcy Cordell
il 22 Gen 2024
Spostato: Dyuman Joshi
il 12 Feb 2024
Dyuman Joshi
il 23 Gen 2024
Spostato: Dyuman Joshi
il 12 Feb 2024
@Darcy Cordell, check this.
t1 = datetime('2023-04-01 04:00:00');
%I've changed the time
t2 = datetime('2023-04-01 05:00:00');
t = t1:seconds:t2;
data = rand(length(t),1);
plot(t,data,'.');
%Use datetick with the 15th Format Identifier, which corresponds to HH:MM
datetick('x', 15);
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Graphics Object Properties in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





