Time format printing too much

2 次查看(过去 30 天)
black
black 2019-9-21
评论: black 2019-9-22
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

采纳的回答

dpb
dpb 2019-9-21
编辑:dpb 2019-9-21
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.

更多回答(0 个)

社区

更多回答在  ThingSpeak Community

类别

Help CenterFile Exchange 中查找有关 Visualize Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by