How can I save a figure as an EPS file without white margins?
83 views (last 30 days)
Show older comments
I want to export a MATLAB figure and include it, as a vector image, and without white margins, in a latex document, therefore I need an eps file. The problem is that sometimes the file obtained using saveas has white margins, sometimes not. For example I noticed a strange behaviour with this code which uses the function scatter3. I'm plotting two points; if the two points have at least one equal coordinate, the resulting EPS file has no margin:
x = [10 10];
y = [100 110];
z = [20 30];
fig = figure;
scatter3(x,y,z)
saveas(fig,"figure_test",'epsc')
while if the two points have no equal coordinates, the resulting EPS has white margins
x = [20 10];
y = [100 110];
z = [20 30];
fig = figure;
scatter3(x,y,z)
saveas(fig,"figure_test",'epsc')
How can I force MATLAB to save the eps file without margin?
3 Comments
BenediktS
on 13 Aug 2023
Yes, I have the same problem with R2021b. Does anybody know if a newer version fixes this problem?
Ramon Abritta Aguiar Santos
on 4 Apr 2024
Using exportgraphics(gcf,'myfigure.eps') works perfectly for me. No undesired white spaces from what I have seen so far. Version R2024a.
Answers (1)
Sreelakshmi S.B
on 8 Mar 2019
You can go through the following link. It explains in detail how to save a figure with minimal white space:
Currently there is no MATLAB command that directly expands the axes to eliminate all of the margins in a figure.
However, this can be accomplished through manipulation of the 'Position', 'TightInset', and optionally 'OuterPosition' properties of the axes and the ‘PaperPosition’ property of the figure.
When you create a graph or display an image, MATLAB automatically creates an axes. The axes is sized to fit in the current figure and there are basically 3 different position vectors associated with the created axes that determine the bounds of the axes. These bounds (gray borders) affect both the display as well as the printing of the figure.
The position vectors associated with the axes are defined as follows:
Position -- The boundary of the axes, excluding the tick marks and labels, title, and axis labels.
OuterPosition -- The boundary of the axes including the axis labels, title, and a margin. For figures with only one axes, this is the interior of the figure.
TightInset -- The margins added to the width and height of the Position property to include text labels, title, and axis labels.
For more information on these axes properties, including a graphical interpretation, you can view the help documentation by executing:
doc axes_props
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!