Using exportgraphics on Figure With Multiple Subplots

82 次查看(过去 30 天)
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
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