Subplots squished to top of page, manually setting position not working

14 vues (au cours des 30 derniers jours)
newbie9
newbie9 le 7 Déc 2019
Commenté : Star Strider le 7 Déc 2019
I am trying to create a set of 12 subplots on a tabloid landscape layout to print to PDF.
The plots are all squished to the top of the page if I don't adjust the positioning. When I do adjust it, the plots disappear.
I don't want to use an outside function from the file exchange. I just want to use my own layout. Using R2018a
No Position Adjustment
x = randperm(40, 8);
y = randperm(10, 8);
g = randi([1,2],8,1);
nplts = 12;
for ii = 1:nplts
ax(ii) = subplot(nplts, 3, ii);
gscatter(x,y,g,'kmbgc')
box on; grid on
xlabel('x', 'FontSize', 10)
ylabel('y', 'FontSize', 10)
plotname = char(strcat('My_Plot', {' '}, num2str(ii)));
title(plotname, 'FontSize', 10, 'Interpreter', 'None')
lgd = legend;
lgd.FontSize = 6; lgd.Location = 'southoutside';
end
With Position Adjustment
x = randperm(40, 8);
y = randperm(10, 8);
g = randi([1,2],8,1);
nplts = 12;
pos1 = [0.5 4.0 7.5 0.5 4.0 7.5 0.5 4.0 7.5 0.5 4.0 7.5];
pos2 = [14 14 14 10 10 10 6 6 6 2 2 2];
wid = 3;
ht = 2;
for ii = 1:nplts
ax(ii) = subplot(nplts, 3, ii);
gscatter(x,y,g,'kmbgc')
box on; grid on
xlabel('x', 'FontSize', 10)
ylabel('y', 'FontSize', 10)
plotname = char(strcat('My_Plot', {' '}, num2str(ii)));
title(plotname, 'FontSize', 10, 'Interpreter', 'None')
lgd = legend;
lgd.FontSize = 6; lgd.Location = 'southoutside';
set(gca, 'units', 'inches')
p = [pos1(ii) pos2(ii) wid ht];
set(gca, 'Position', p)
end
<< blank figure >>

Réponse acceptée

Star Strider
Star Strider le 7 Déc 2019
The code tells subplot to plot 12 rows and 3 columns.
Try this instead:
ax(ii) = subplot(nplts/3, 3, ii);
The result is much more readable!
  2 commentaires
newbie9
newbie9 le 7 Déc 2019
oh my gosh, what a dumb mistake... so obvious now, thank you
Star Strider
Star Strider le 7 Déc 2019
As always, my pleasure!
You are not the first person to make that mistake!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Labels and Annotations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by