Why is one of my subplots being deleted?
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
The second subplot is deleted after setting the first, but why? The bottom of the first subplot is at 0.3, whereas the top of the second subplot is at 0.19. There shouldn't be any overlap that would result in deletion.
figure;
ax1 = subplot(2,1,1,'Position', [0.05, 0.3, 0.92, 0.64]);
ax2 = subplot(2,1,2,'Position', [0.05, 0.09, 0.92, 0.1]);
Also, I get the following warning:
Warning: subplot ignores grid location arguments when Position is specified. This syntax will no longer be supported in a future release.
0 commentaires
Réponse acceptée
Les Beckham
le 25 Fév 2022
Modifié(e) : Les Beckham
le 25 Fév 2022
If you know the position of the two axes already, you don't need to use the subplot function to position them for you.
Just do this:
figure
ax(1) = axes('position', [0.05, 0.3, 0.92, 0.64]);
ax(2) = axes('position', [0.05, 0.09, 0.92, 0.1]);
Note that I created ax as an array of axis handles.
Now you can plot into those axes.
plot(ax(1), 0:0.01:2*pi, sin(0:0.01:2*pi))
plot(ax(2), 0:10, 0:10)
0 commentaires
Plus de réponses (2)
Voss
le 25 Fév 2022
The problem: only one axes was created
figure;
ax1 = subplot(2,1,1,'Position', [0.05, 0.3, 0.92, 0.64]);
ax2 = subplot(2,1,2,'Position', [0.05, 0.09, 0.92, 0.1]);
findall(gcf(),'Type','axes')
% (only one axes was created)
A solution: if you are specifying the positions directly, you can use axes() directly to create the axes rather than subplot():
figure;
ax1 = axes('Parent',gcf(),'Units','normalized','Position',[0.05, 0.3, 0.92, 0.64]);
ax2 = axes('Parent',gcf(),'Units','normalized','Position', [0.05, 0.09, 0.92, 0.1]);
findall(gcf(),'Type','axes')
% (two axes were created)
0 commentaires
Voir également
Catégories
En savoir plus sur Subplots 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!