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);
  1 件のコメント
Kamal Premaratne
Kamal Premaratne 2021 年 7 月 8 日
That's it. Worked like a charm. Thank you so much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by