exportgraphics: adding a margin
180 views (last 30 days)
Show older comments
Is it possible to add a margin to figures saved using the exportgraphics function?
It crops a tad too tightly for my needs.
0 Comments
Answers (2)
Paul Wintz
on 15 Sep 2021
Edited: Paul Wintz
on 18 Nov 2021
You can force exportgraphics to export the entire figure by drawing an white rectange around it with the command
annotation('rectangle',[0 0 1 1],'Color','w');
To adjust the margins, change the dimensions [0 0 1 1].
As noted by @David Walwark in the comments, the plot will not be interactive while it is annotated. To restore interactivity, delete the annotation after calling exportgraphics.
a = annotation('rectangle',[0 0 1 1],'Color','w');
% -> Save figure here <-
delete(a)
2 Comments
David Walwark
on 17 Nov 2021
Excellent, this really helped. If one wants the figure to remain interactive then it is best to delete the handle to that annotation after exportgraphics is called.
Kiran Felix Robert
on 24 Jun 2021
Hi Dormant,
If you are trying to export multiple sub-images/plots onto a single figure, you can explore the tiledlayout to introduce spacing using the 'TileSpacing' Name-Value pair.
1 Comment
Paul Wintz
on 15 Sep 2021
This doesn't answer the question. How do we adjust the margins on the outside of a figure saved with exportgraphics?
See Also
Categories
Find more on Printing and Saving 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!