Using exportgraphics on Figure With Multiple Subplots

77 vues (au cours des 30 derniers jours)
Kamal Premaratne
Kamal Premaratne le 8 Juil 2021
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.

Réponse acceptée

Johannes Hougaard
Johannes Hougaard le 8 Juil 2021
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 commentaire
Kamal Premaratne
Kamal Premaratne le 8 Juil 2021
That's it. Worked like a charm. Thank you so much.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Printing and Saving dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by