Missing subplots inside a panel
이전 댓글 표시
I am trying to draw some interfaces programmatically. I am blocked with a problem that I cannot fix. I need to draw several graphs with the characteristic that the number of subplots is variable and they have to be inserted inside a panel that uses a slider to enable the visualization of all of them. The problem is that although the drawing zone size is calculated correctly, it does not draw after position 0.63 (being 1 the end of the panel). Here is the code of my .m file and the images of the obtained result:
<<

>>
function SliderHor()
% make the GUI fullscreen
set(0,'units','pixels');
pix = get(0,'screensize');
w = pix(3);
h = pix(4);
set(gcf,'units','pixels','outerposition',[50 50 w-100 h-100]);
set(gcf, 'NumberTitle', 'off', 'Name','Graphs', 'MenuBar', 'none', 'ToolBar', 'none');
%Create the panel and the slider
panel1 = uipanel('Position',[0.05 0.15 0.9 0.8]);
panel2 = uipanel('Parent',panel1, 'Position',[0 0 2 1]);
s = uicontrol('Style','Slider','Parent',panel1,'Units','normalized',...
'Position',[0 0 1 0.05],'Value',0,'Callback',{@slider_callback1,panel2});
% paint the graphs
nReplicas = 10;
replicaW = 1/nReplicas;
for j=1:nReplicas
% data
x = 0: .1 : 2*pi;
y1 = cos(x);
y2 = sin(x);
% Draw each cell data
xpos = (j-1)*replicaW + replicaW/6;
subplot(1,2*nReplicas,(2*j)-1,'Parent',panel2,'Position',[xpos,0.2,replicaW/3,0.6]);
% Plot y1 vs. x (blue, solid) and y2 vs. x (red, dashed)
plot(x, y1, 'bs');
% Add title and axis labels
xlabel('angle')
ylabel('cos(x)')
title(sprintf('Replica %d',j))
xpos2 = (j-1)*replicaW + replicaW/6 + replicaW/3;
subplot(1,2*nReplicas,2*j,'Parent',panel2,'Position',[xpos2,0.2,replicaW/3,0.6]);
plot(x,y2,'r-','LineWidth',2);
xlabel('angle')
ylabel('sin(x)')
title(sprintf('Replica %d',j))
end
% callback function
function slider_callback1(src,eventdata,arg1)
val = get(src,'Value');
set(arg1,'Position',[-val 0 2 1])
end
end
채택된 답변
추가 답변 (1개)
Adam
2016년 6월 23일
I very rarely use subplot and that behaviour I cannot understand on stepping through. However, you do not need to complicate issues by using subplot, just create axes and it seems to work fine - i.e.
Replace this:
subplot(1,2*nReplicas,(2*j)-1,'Parent',panel2,'Position',[xpos,0.2,replicaW/3,0.6]);
with this:
axes( 'Parent',panel2,'Position',[xpos,0.2,replicaW/3,0.6] );
and the equivalent for the 2nd plot of a pair too.
I would recommend keeping the axes handle you create and referring to it explicitly for plotting though anyway - e.g.
hAxes = axes( 'Parent',panel2,'Position',[xpos,0.2,replicaW/3,0.6] );
plot(hAxes, x, y1, 'bs');
% Add title and axis labels
xlabel(hAxes, 'angle')
ylabel(hAxes, 'cos(x)')
title(hAxes, sprintf('Replica %d',j))
댓글 수: 5
Elisa Prada
2016년 6월 23일
Adam
2016년 6월 23일
I could see all the graphs when I ran it, but only when using axes. Using subplot the 7th and onwards started replacing removing the previous plots for reasons I couldn't understand.
Elisa Prada
2016년 6월 23일
Elisa Prada
2016년 6월 23일
Adam
2016년 6월 23일
I am using R2016a, but I also tested in R2015a
카테고리
도움말 센터 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
