- 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?
53 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Richard Quist
2022 年 5 月 2 日
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 件のコメント
Riccardo Scorretti
2022 年 4 月 12 日
編集済み: Riccardo Scorretti
2022 年 4 月 12 日
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 件のコメント
参考
カテゴリ
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!