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

 采纳的回答

Adam
Adam 2016-6-23

0 个投票

Works fine for me using axes rather than subplot in R2015a too so doesn't look like a version issue.

2 个评论

Ok, I do not understand it. Could you please include the .m you are using?
I have removed the screensize part and it works, I can see all the graphs . Thanks a lot for your help!

请先登录,再进行评论。

更多回答(1 个)

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 个评论

I have tried with axes too but it happens the same. Have you run it? Can you see all the graphs? I have just tried it again and I can only see until "Replica 6".
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.
I cannot see them. I am using Matlab R2015a and I have also tried in Matlab R2014b. Can it be a version problem??
I have tried in R2013a and it draws from 1 to 6 and also the last one (the 10th)
Ca you please tell me the version you are using?
I am using R2016a, but I also tested in R2015a

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by