- use MATLAB's exportgraphics command which was introduced in R202a (first example below)
- Set the figure renderer to 'painters' before saving (second example below)
How do I get rid of space above figure?
49 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello
I am trying to print and save the figure as an EPS-file. This works fine but the figure comes out with a hugh blank space above it.
Can someone help me remove this?
0 comentarios
Respuestas (2)
Richard Quist
el 2 de Mayo de 2022
MATLAB-generated EPS files are usually tightly cropped by default, which should have eliminated that extra space above your plot in the output file. Using either of the following should ensure that this occurs:
% This example assumes that 'fig' is the handle to your figure.
% In R2020a and later, you can use the exportgraphics command and specify
% the 'ContentType' as 'vector' (to ensure tightly cropped, scalable output):
exportgraphics(fig, 'output.eps', 'ContentType', 'vector');
% This example assumes that 'fig' is the handle to your figure.
% Change the figure renderer to 'painters' before saving the file
fig.Renderer = 'painters';
I hope that helps.
0 comentarios
Riccardo Scorretti
el 12 de Abr. de 2022
Editada: Riccardo Scorretti
el 12 de Abr. de 2022
Hi Tobias,
I had a similar problem (but I save images in .png format). I can propose the method I solved it:
- I save the image with a resolution of 300 dpi by using: print my_wonderful_image.png -dpng -r300
- I import the image by using Gimp, I crop the image and save back to the .png format.
It's not elegant, it's rather messy, but it works. I can use the images generated in this way with both LaTeX and MS Word, event to make A0 format posters, and the size of files are reasonable. In the images below: before cropping (left) and after cropping (right). The size of the two images is approximately the same, but the image on the left has some white space.
Of course this method will not work if you need to save the whole figure (= with the title, and the GUI elements). In this case, you can tweak the figure by modifying the property Position of the axes:
% Create the figure
t = linspace(0, 2*pi, 256);
plot(t, sin(t));
xlabel('t', 'FontSize', 16);
ylabel('sin(t)', 'FontSize', 16);
% Tweak the position
ax = gca ; ax.Position = [0.11 0.11 0.87 0.87];
Hereafter the two figures (= before and after tweaking the position):
0 comentarios
Ver también
Categorías
Más información sobre Printing and Saving en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!