Exporting figures with minimal whitespace via exportgraphics() works only for .png, but not for .eps or .pdf format?
조회 수: 36 (최근 30일)
이전 댓글 표시
I'm trying to create some plots and output them out as .eps or .pdf files, with the whitespace properly detected and removed. As I'm running a new enough version of MATLAB (R2021b), I have used the guide Save Plot with Minimal White Space. However, this only works when exporting as .png, otherwise there is plenty of whitespace left. I've also provided a simple example code, which, for me, outputs three files, and only the .png file is actually cropped to remove the whitespace.
My question is if I'm doing something wrong, and is there any way to get the same effect for .eps or .pdf files?
z = peaks(25);
figure
mesh(z)
set(gca, 'Visible', 'off')
% Png file
exportgraphics(gcf,'AnnotatedPlot.png')
% Pdf file
exportgraphics(gcf,'AnnotatedPlot.pdf')
% Eps file
exportgraphics(gcf,'AnnotatedPlot.eps')
댓글 수: 1
Jonas
2023년 11월 23일
you could try
set(gca, 'LooseInset', get(gca, 'TightInset'));
before exporting to eps or pdf
답변 (1개)
Sandeep Mishra
2024년 9월 6일
Hi,
It appears that you are encountering an issue with the 'exportgraphics' function, where exporting a 'figure' to PDF and EPS file format results in unwanted white spaces.
To address this problem, you can modify the 'ContentType' property of the 'exportgraphics' function to 'vector'. This adjustment helps minimize the white spaces in the exported figures.
Below is the code snippet illustrating how to implement this approach:
% Export as PDF
exportgraphics(gcf,'AnnotatedPlot.pdf','ContentType','vector')
% Export as EPS
exportgraphics(gcf,'AnnotatedPlot.eps','ContentType','vector')
Please refer to the below documentation to learn more about ‘ContentType’ property of ‘exportgraphics’ function in MATLAB: https://www.mathworks.com/help/releases/R2021b/matlab/ref/exportgraphics.html#mw_5bdc680e-deea-429e-b58e-24e3de1083f7
I hope this helps.
댓글 수: 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!