필터 지우기
필터 지우기

How can I save a figure as an EPS file without white margins?

조회 수: 84 (최근 30일)
Alessio Mora
Alessio Mora 2019년 3월 5일
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
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
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