Time format printing too much

2 vues (au cours des 30 derniers jours)
black
black le 21 Sep 2019
Commenté : black le 22 Sep 2019
I want to label the time axis in a plot with "ddd: HH" (speak "first three letters of the day, then the two digits for the hour in 24-hour format).
However, when doing this, the format is applied for some labels, but otheres also print more information like month, day and year.
% generate time sequence, last 3 days, 12 hours offset
xtickformat('eee: HH')
t2 = datetime('today'),
t1 = t2-days(3)
xData = t1:hours(12):t2
set(gca,'xtick',xData)
Leads to:
Screenshot 2019-09-21 at 10.00.55.png

Réponse acceptée

dpb
dpb le 21 Sep 2019
Modifié(e) : dpb le 21 Sep 2019
I presume your complaint is the range label automagically shown for datetime axes. Seems there should be a way for user to turn that on/off, but doesn't appear to be...
The following generates
t2 = datetime('today');
t1 = t2-days(3);
xData = t1:hours(12):t2;
hL=plot(xData,randn(size(xData)));
xticks(xData)
xtickformat('eee: HH')
hAx=gca; % get current axes handle
hXAx=hAx.XAxis; % retrieve handle to xaxis datetime ruler object
hXAx.SecondaryLabel.String=''; % set the limits label string to empty
The SecondaryLabel property is hidden one -- used the FEX submission of Yair Altman to discover the name of the nondisclosed properties.
NB: Until the axes is created as a datetime ruler object, xtickformat will fail as will xticks as default requires double. At least thru R2017b here--perhaps later releases will automagically convert the axis type as needed; can't test that here but I'd be somewhat surprised.
  1 commentaire
black
black le 22 Sep 2019
Thank you! This solved it.

Connectez-vous pour commenter.

Plus de réponses (0)

Communautés

Plus de réponses dans  ThingSpeak Community

Catégories

En savoir plus sur Visualize Data dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by