Using exportgraphics on Figure With Multiple Subplots

조회 수: 85 (최근 30일)
Kamal Premaratne
Kamal Premaratne 2021년 7월 8일
댓글: Kamal Premaratne 2021년 7월 8일
I have a figure which has 1 x 3 subplots. I want to get a high resolution pdf file (for publication purposes) which contains all the subplots. However, when I use
>> exportgraphics('filename.pdf')
the pdf file created has only part of the figure. I would appreciate receiving advise on how to generate a high-resolution pdf file which contains the full figure (in this case, with 3 subplots). Thanks.

채택된 답변

Johannes Hougaard
Johannes Hougaard 2021년 7월 8일
What you need to do is to provide an input to exportgraphics to take the figure rather than the axes
When calling exportgraphics with no handle-style input it just exports 'gca' (the last active axes handle)
This should do the trick (using f as the figure handle but you could theoretically just use gcf as your input to exportgraphics)
filename = 'thisisadpdffile.pdf';
x = linspace(-pi*9,pi*9,999);
f = figure;
subplot(2,2,1);
plot(x,sin(x));
subplot(2,2,2);
plot(x,sin(x./2),'color',[155 0 0]/255);
subplot(2,2,[3 4]);
plot(x,cos(x));
hold on
plot(x,1./x);
exportgraphics(f,filename);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by