필터 지우기
필터 지우기

Why is one of my subplots being deleted?

조회 수: 18 (최근 30일)
L'O.G.
L'O.G. 2022년 2월 25일
편집: Matt J 2022년 2월 25일
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.

채택된 답변

Les Beckham
Les Beckham 2022년 2월 25일
편집: Les Beckham 2022년 2월 25일
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)

추가 답변 (2개)

Voss
Voss 2022년 2월 25일
The problem: only one axes was created
figure;
ax1 = subplot(2,1,1,'Position', [0.05, 0.3, 0.92, 0.64]);
Warning: subplot ignores grid location arguments when Position is specified. This syntax will no longer be supported in a future release.
ax2 = subplot(2,1,2,'Position', [0.05, 0.09, 0.92, 0.1]);
Warning: subplot ignores grid location arguments when Position is specified. This syntax will no longer be supported in a future release.
findall(gcf(),'Type','axes')
ans =
Axes with properties: XLim: [0 1] YLim: [0 1] XScale: 'linear' YScale: 'linear' GridLineStyle: '-' Position: [0.0500 0.0900 0.9200 0.1000] Units: 'normalized' Show all properties
% (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')
ans =
2×1 Axes array: Axes Axes
% (two axes were created)

Matt J
Matt J 2022년 2월 25일
편집: Matt J 2022년 2월 25일
Not sure, but I think you're better off using tiledlayout(),
tiledlayout(74,1)
ax1 = nexttile([64,1]);
ax2 = nexttile([10,1]);
plot(ax1, 0:0.01:2*pi, sin(0:0.01:2*pi))
plot(ax2, 0:10, 0:10)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by