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

85 Ansichten (letzte 30 Tage)
Alessio Mora
Alessio Mora am 5 Mär. 2019
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 Kommentare
BenediktS
BenediktS am 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
Using exportgraphics(gcf,'myfigure.eps') works perfectly for me. No undesired white spaces from what I have seen so far. Version R2024a.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sreelakshmi S.B
Sreelakshmi S.B am 8 Mär. 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
  1 Kommentar
Alessio Mora
Alessio Mora am 11 Mär. 2019
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Printing and Saving finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by