How can I save a figure as an EPS file without white margins?
89 次查看(过去 30 天)
显示 更早的评论
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 个评论
BenediktS
2023-8-13
Yes, I have the same problem with R2021b. Does anybody know if a newer version fixes this problem?
Ramon Abritta Aguiar Santos
2024-4-4
Using exportgraphics(gcf,'myfigure.eps') works perfectly for me. No undesired white spaces from what I have seen so far. Version R2024a.
回答(1 个)
Sreelakshmi S.B
2019-3-8
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!