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
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
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
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
  1 个评论
Alessio Mora
Alessio Mora 2019-3-11
Thanks for the answer! However I already read that page and I had problems since I wanted to have the same length for the data units in the different axes.
The fact is that if you test my first code you can see that MATLAB automatically removes the white margins, while in the second one it does not. It would be great to understand how to apply this "cut" every time.
An alternative would be to execute another program (maybe written in MATLAB but also in another language) which cuts the margins after generating the eps.
which can cut the margin but I had some problems with the background color

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by