Problem creating axes with subplot

조회 수: 6 (최근 30일)
RABEHI
RABEHI 2014년 8월 31일
댓글: Danylyna Shpakivska 2023년 3월 12일
I have a little problem with subplot. Indeed, I try to create 8 axes using the commande subplot, I write this :
subplot(4,2,1,'position',[0.2 0.3 0.05 0.12]);
subplot(4,2,2,'position',[0.3 0.3 0.05 0.12]);
....
until the 8th axes. But, when I run the programme, I get only 6 axes ! the lack is the first and the seconde. Why I have this problme ?
  댓글 수: 2
dpb
dpb 2014년 8월 31일
Don't show all so can't replicate but the odds are you've got overlapping position coordinates which by the doc's
help subplot
...
If a subplot specification causes a new axes to overlap an
existing axes, the existing axes is deleted...
Danylyna Shpakivska
Danylyna Shpakivska 2023년 3월 12일
thanks, that solved the problem!

댓글을 달려면 로그인하십시오.

답변 (3개)

Joseph Cheng
Joseph Cheng 2014년 8월 31일
So just like dpb said there is something going on with the subplot and when it is called it may delete the previous axes. Here is an example of what you can do instead of using subplot. Since you're specifying the location using subplot really isn't necessary anymore.
clc
clear all;
Sampimg{1} = rand(100);
Sampimg{2} = repmat(1:100,100,1);
Sampimg{3} = repmat([1:50 50:-1:1],100,1);
Sampimg{4} = repmat([1:50 50:-1:1]',100,1);
Sampimg{5} = rand(100);
Sampimg{6} = repmat(1:100,100,1);
Sampimg{7} = repmat([1:50 50:-1:1],100,1);
Sampimg{8} = repmat([1:50 50:-1:1]',100,1);
subplotMxN = [8];
for Mind = 1:subplotMxN(1)
handles.SubPlot(Mind) = axes;
set(handles.SubPlot(Mind),'Position',[.1+Mind/10 .3 .05 .12])
imagesc(Sampimg{Mind});
end
if you go to another Question asked this week http://www.mathworks.com/matlabcentral/answers/152366-question-about-axes-using-gui-in-matlab I create one that can somewhat do a MxN subplot.
  댓글 수: 2
Image Analyst
Image Analyst 2014년 8월 31일
Joseph, can you adapt your code to put the plots in a 4 row by 2 column array like he tried to do with subplot, instead of all in one row?
Joseph Cheng
Joseph Cheng 2014년 9월 1일
That was done in my previous answered question. Here i was just extrapolating his/her
subplot(4,2,1,'position',[0.2 0.3 0.05 0.12]);
subplot(4,2,2,'position',[0.3 0.3 0.05 0.12]);
by incrementing the x position based on the information i had. The linked version contains something that would try to fit it to their needs. however since i had the time. here we go
clc
clear all;
Sampimg{1} = rand(100);
Sampimg{2} = repmat(1:100,100,1);
Sampimg{3} = repmat([1:50 50:-1:1],100,1);
Sampimg{4} = repmat([1:50 50:-1:1]',100,1);
Sampimg{5} = rand(100);
Sampimg{6} = repmat(1:100,100,1);
Sampimg{7} = repmat([1:50 50:-1:1],100,1);
Sampimg{8} = repmat([1:50 50:-1:1]',100,1);
subplotMxN = [2 4];
width = .05;
height = 0.12;
xSpace = .1;
ySpace = .24;
plotind=1;
for Mind = 0:subplotMxN(1)-1
for Nind = 0:subplotMxN(2)-1
handles.SubPlot(plotind) = axes;
subpos = [0.2+xSpace*Nind 0.3+ySpace*Mind width height];
set(handles.SubPlot(plotind),'Position',subpos)
imagesc(Sampimg{plotind});
plotind = plotind+1;
end
end

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2014년 8월 31일
Please show all 8 of the calls to subplot. If they're in a loop, then make position a variable and have it print to the command line. Like dpb says, chances are some of the plots overlap and won't get shown. You might use uicontrol() or something to create new axes instead of subplot. Perhaps axes created that way won't have this overlap/not-shown problem - I don't know, I'd have to test. That's (almost) what Joseph's code shows you, except they're all in a line instead of a 4x2 array.

Mike Garrity
Mike Garrity 2014년 9월 4일
One of the features of subplot is that when it creates a new axes it deletes any old ones which the new one would overlap. If you don't want this feature, then you can just call the axes command directly. It won't do this overlap check.
Your code would look something like this:
axes('Position',[0.2 0.3 0.05 0.12]);
axes('Position',[0.3 0.3 0.05 0.12]);
...

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by