How can I get rid of the gap on the x-axis?

Dear all,
I have the following code which results in the shown graph. However, I would like to make the graph prettier by avoiding the gap at the end of the x-axis as well as bigger spacing between the x-ticks and x-labels. Help is much appreciated :-)
app.UIAxesThUeberschuss.XLimMode = 'auto';
app.UIAxesThUeberschuss.YLimMode = 'auto';
app.UIAxesThUeberschuss.XTick = (0:hournum:projectlengthhour); % needed to show years instead of hours
app.UIAxesThUeberschuss.XTickLabel = (0:projectlength); % needed to show years instead of hours
zoom(app.UIAxesThUeberschuss,'on');
plot(app.UIAxesThUeberschuss,1:projectlengthhour,P_ueber.th);
Info:
  • hournum = 8760
  • projectlength = 30
  • projectlengthhour = 262800 (=hournum * projectlength)
  • P_ueber.th is a 262800x1 vector

5 Comments

you can use xlim to get rid of the gap.
Consider rotating the tick font 90 degrees. https://www.mathworks.com/help/matlab/ref/xtickangle.html
hello Maria
for the first point , try to switch from 'auto' to 'manual' and specify the range
Current limits mode, returned as one of these values:
  • 'auto' — Automatically determine the limits.
  • 'manual' — Use manually specified limits that do not update to reflect changes in the data.
For the second point , you have to increase the x spacing
for the time being I assume from the plot x axis, that hournum = 1
try now with an increased value , for example hournum = 5 , now you should see only 0,5,10,... values , which makes the whole axis more readable
you have also to update the XTickLabel with the new spacing :
app.UIAxesThUeberschuss.XTickLabel = (0:hournum:projectlength);
Hello Mathieu and Walter,
switching to manual would not work as the projectlength and projecthour can be both adusted in the app.
Manual is configured automatically if you use xlim(). You would xlim() passing in the min() and max() of the x data, which often would correspond to the first and last x values.
Nice, I tried
app.UIAxesPV_ungeordnet.XLim = [0 projectlengthhour];
and it worked. Thanks!

Sign in to comment.

Categories

Find more on Graphics 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!