Time format printing too much
2 次查看(过去 30 天)
显示 更早的评论
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:
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Visualize Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!