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

 Réponse acceptée

Adam
Adam le 23 Juin 2016

0 votes

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

2 commentaires

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

Connectez-vous pour commenter.

Plus de réponses (1)

Adam
Adam le 23 Juin 2016

0 votes

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 commentaires

Elisa Prada
Elisa Prada le 23 Juin 2016
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".
Adam
Adam le 23 Juin 2016
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
Elisa Prada le 23 Juin 2016
I cannot see them. I am using Matlab R2015a and I have also tried in Matlab R2014b. Can it be a version problem??
Elisa Prada
Elisa Prada le 23 Juin 2016
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?
Adam
Adam le 23 Juin 2016
I am using R2016a, but I also tested in R2015a

Connectez-vous pour commenter.

Catégories

En savoir plus sur Line Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by