MATLAB Answers

White space at the beginning and ending of xaxis

23 views (last 30 days)
Happy Bear
Happy Bear on 13 Jul 2020 at 17:03
Commented: Adam Danz on 13 Jul 2020 at 18:11
Hello everyone,
I made this graph but I want to have some white spacing between the yaxis and the first bin. And then I want some white spacing between the last bin and the right axis of the figure. Just like in this figure:

  0 Comments

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 13 Jul 2020 at 17:46
Edited: Adam Danz on 13 Jul 2020 at 17:51
axis(ax, 'tight') % where ax is your axis handle.
will set the axis limits so the edges of the plot touch the max and min of your data.
After running that command, you can run the lines below to add +/- 5% of your data range to each side of the x and y axes.
xlim(ax, xlim(ax) + [-1,1]*range(xlim(ax)).* 0.05)
ylim(ax, ylim(ax) + [-1,1]*range(ylim(ax)).* 0.05)
If you only want to apply this to the x-axis limits,
yl = ylim(ax);
axis(ax, 'tight')
ylim(ax, yl)
xlim(ax, xlim(ax) + [-1,1]*range(xlim(ax)).* 0.05)

  4 Comments

Show 1 older comment
Adam Danz
Adam Danz on 13 Jul 2020 at 18:04
Glad I could make the Happy Bear happy :)

Sign in to comment.

More Answers (0)