Using print to export matlab figures to pdf: How to KEEP borders (and not crop them)
조회 수: 7 (최근 30일)
이전 댓글 표시
I am trying to export a matlab figure to a pdf file using print function.
set(gcf, 'InvertHardCopy', 'off', 'PaperType', 'usletter');
print(gcf, 'sample_output', '-dpdf', '-r400');
The output I see is of acceptable quality but the usual white space around figure is cropped in the output. I want to keep the surrounding space.
Any help would be great!
댓글 수: 0
답변 (1개)
Alec Jacobson
2020년 10월 18일
This question has been asked many times with zero answers that I could find. Here's a hacky partial work around for 2D plots where a single axis fills the full figure window. It will add a line from the bottom-left corner to the top-right so when MATLAB crops the figure (without asking) it will have no choice but to leave the everything alone.
% add a white line from corner to corner
hold on;plt(reshape(axis,[],2),'-w');hold off;
% put it in the back
set(gca,'Children',circshift(get(gca, 'Children'),-1));
% print to .eps file
print('foo.eps','-depsc');
Assumes background is white and manipulates the current axis and figure. Would be great to see MATLAB address this problem (or point out an existing solution).
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!