How to get rid of the date on a plot over time?

16 views (last 30 days)
Hello Matlab-Pros,
I want to plot values over time, but I matlab always adds the day to the axis description.
How can I get rid of this date?
That's my (very easy) code:
x = (linspace(StartT,EndT,IndexFinalDepth));
x.Format = 'HH:mm:ss';
y = (-1)*(RawData(1:IndexFinalDepth,1));
TimePlot = subplot(ax1);
plot(x,y)
ylim ([(-maxDepth-2) 0]);
xlim auto
ylabel('Elevation [m]','FontSize',7)
set(gca,'fontsize',7)
TimePlot.Title.String = 'Depth Profile';
TimePlot.Title.FontWeight = 'normal';
TimePlot.Title.FontSize = 7;
Thanks in advance!
Mike

Accepted Answer

dpb
dpb on 17 May 2018
Can't by just using the format string for the datetime ruler object; it will put whatever is needed to make the date labels unique. You can, however, write the XTickLabel property and that overrides the XTick display...
TimePlot = subplot(ax1);
plot(x,y)
x.Format='HH:mm';
TimePlot.XTickLabel=cellstr(x);
....
>>
  2 Comments
Michael Steinbuechler
Michael Steinbuechler on 17 May 2018
Works like a charm! Thank you very much.
I just realized that changing the date format the way I did it before, doesn't affect the outcome at all.
dpb
dpb on 17 May 2018
That's correct; that only affects the display of the object; you can change the format of the axis time ruler with the xtickformat function or the '.TickLabelFormat' property, but the datetime ruler has a mind of its own regarding that it thinks it must somehow make the times shown unambiguous despite what you tell it you want.
Only writing specifically the text in the label property that isn't tied to the tick value overrides that "feature". I had fairly long conversation with a TMW staffer a few weeks ago on the subject and suggested that be made user-settable (whether will take the advice is anybody's guess :) ).

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!