plotting x axis with matched array numbers.
2 views (last 30 days)
Show older comments
sermet
on 12 Jan 2017
Answered: Walter Roberson
on 12 Jan 2017
PDOP=[1.31;1.33;1.26;1.27;1.29;1.30;1.30;1.29;1.25;1.35;1.24;1.25;1.42];
time_array=[3 23 30;3 23 45;4 0 0;4 0 15;4 0 30;4 0 45;4 1 0;4 1 15;4 1 30;4 1 45;4 2 0;4 2 15;4 2 30];
time_format=duration(time_array,'Format','hh:mm:ss'); % days:hour:minute
figure(1)
plot(time_format,PDOP,'c','LineWidth',1.75)
when I plot the data, how can I show only time_format numbers on the x-axis instead of other intervening numbers?
4 Comments
Walter Roberson
on 12 Jan 2017
Which MATLAB version are you using? There were relevant changes in recent releases.
In R2016b the only numbers I see on the X axis are in the format you indicate you want.
Accepted Answer
Walter Roberson
on 12 Jan 2017
When you use a datetime or duration object for an axes, the default tick labels depend upon the size of your axes. You are seeing ticks every 5 minutes; if your window were narrower you would see them every 10 minutes.
You have asked to show only the times in duration_format . Unfortunately those times are bunched close together in two different places with a relatively large gap between the places. You probably will not be able to make your axes window wide enough to be able to see the separate ticks labeled. But if you want to try then proceed as follows:
This information is for R2015a only and will not work without changes in any other release.
After your plot, do
ax = gca;
xrule = ax.XRuler; %this part is specific to R2015a, in R2015b it become XAxis
xrule.TickLabelRotation = 90;
xrule.Tick = days(time_format); %this part is specific to earlier HG2, in later HG2 the ticks became duration objects directly
Unfortunately if you resize the axes, then the ticks will be automatically chosen again and you would need to assign to Tick again. I think that might have been an R2015a bug.
0 Comments
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!