Subplots within a GUI figure

I am developing a GUI using GUIDE. I have three axes defined in GUI. two of them I filled with two plots. The third axes, however, I would like to divide into several subplots. The problem is everytime I try to use it the subplot is dividing the entire GUI figure into several plots which is not what I wanted. Basically I have Axes1 which I filled with a figure, and Axes2 which I filled with another figure. and Now I have Axes3 which i like to divide into say 2x2 subplots. How do I do it?

7 comentarios

John Chilleri
John Chilleri el 10 de Feb. de 2017
Haven't considered this before, but without looking into it, you could always just construct your fig with four plots in that area, which should essentially have the same effect (there's probably a better way though).
Pappu Murthy
Pappu Murthy el 10 de Feb. de 2017
I understand what you are saying however this will have a drawback. Because the number of plots could be a variable in which case dividing the acreage appriori into so many figures is not a good idea! Suppose I allot 4 figures in 2x2 matrix where instead of subplots they all wil be separate axes. And now I get into a problem which requires showing 6 figures then i am stuck.
John Chilleri
John Chilleri el 10 de Feb. de 2017
Editada: John Chilleri el 10 de Feb. de 2017
You can find a discussion here, and a solution here. I think the latter is what you're looking for!
Pappu Murthy
Pappu Murthy el 11 de Feb. de 2017
Thanks the suggested procedure works fine for first time around. Let me explain, suppose I have 5 subplots and I divide area by 3x3 and it fills the 5 slots. Now suppose I change the number of subplots to 3 instead for 5 and make it 2x2 ... now I have a problem because it does not clear the previous ones totally and it becomes a mess.. this is clearly evident if I change from 4 to 3 then the 4th one will have something on it although i am expecting only 3 plots. So my question is how do I completely clear and start afresh again?
John Chilleri
John Chilleri el 11 de Feb. de 2017
Perhaps you could employ the cfa command, which should reset your axes. :)
Pappu Murthy
Pappu Murthy el 11 de Feb. de 2017
cla command did work on my other two axes I have but not the one on Panel. I tried cla(handles.Sens.Children,'reset') but it only removed the graphics objects but still shows empty x and y axis.. when I tried to reduce from 3 plots to two plots for e.g... I had 2x2 subplots with three of the full then I chose to show 2 then it showed 2 graphs but it still keeps the 3rd one with bare x and y axis.
Pappu Murthy
Pappu Murthy el 4 de Mzo. de 2017
John Chilleri's comment helped me solve my problem successfully. I used the panel method suggested in the link provided in his comment.

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 11 de Feb. de 2017

0 votos

Pappu, is this what you mean:
% Plot top plot.
subplot(2, 2, 1);
plot(1:10, 'bo-');
title('subplot(2, 2, 1)');
% Plot middle plot.
subplot(2, 2, 2);
plot(sind(1:80), 'rd-');
title('subplot(2, 2, 2)');
% Plot 4 more plots in the bottom left spot
subplot(4, 4, 9);
scatter(rand(1,40), rand(1,40));
title('subplot(4, 4, 9)');
subplot(4, 4, 10);
plot(exp(1:10)/30000, 'ko-');
title('subplot(4, 4, 10)');
subplot(4, 4, 13);
plot(exp(rand(1,10)), 'co-');
title('subplot(4, 4, 13)');
subplot(4, 4, 14);
plot(exp(1:-.1:0), 'go-');
title('subplot(4, 4, 14)');

4 comentarios

Pappu Murthy
Pappu Murthy el 11 de Feb. de 2017
I am sorry but this is not what I am trying to achieve or asking. I understand how to do this. however when you use Guide and create this sort of thing it does not quite work that way.
Image Analyst
Image Analyst el 11 de Feb. de 2017
Then mock up a screenshot of what you do want, because no one knows.
Pappu Murthy
Pappu Murthy el 11 de Feb. de 2017
here it is:
Pappu Murthy
Pappu Murthy el 11 de Feb. de 2017
In the above the first two are two separate axes and i have figures. the third one (right most) is the one i would like to dynamically partition. It could be 2x2, or 3x3 or 4x4 depending on the situation. RIght now I am able to do this just once but the second time around when I try to change the number of subplots, the previous ones are not getting cleanly erased. I have this on a separate UiPanel as per one of the suggestions. hope that helps and you can see why the proposed answer does not work for me here.

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 11 de Feb. de 2017

0 votos

You need to put two panels on your GUI. One will contain the single large axes, and the other will contain the 4 small axes. Then you just set the visible property to 'on' or 'off' to show whichever you want
% Show 4 axes
handles.panelFour.Visible = 'on'; % Show 4 axes.
handles.panelOne.Visible = 'off'; % Hide large axes.
% Show single large axes
handles.panelFour.Visible = 'off'; % Hide 4 axes.
handles.panelOne.Visible = 'on'; % Show large axes.

4 comentarios

Pappu Murthy
Pappu Murthy el 12 de Feb. de 2017
Ok. Let me try to explain again. In the picture the first two are simple plots on two axes. This part of my code is fine. Thext part is the big orange box where depending on number of levels chosen by user i need devide my panel appropriately. For ex. If 4 levels are chosen the i devide the areainti 2x2 subplots. Now suppose user decides to chose 3 levels, i need to clean up the plots from before and devide the area to 2x2 subolots same as before but i fill only three slots. However i am not able to do this cleanly at all. Some of the remnants of previous plots are still there and it is driving me nuts.
Image Analyst
Image Analyst el 12 de Feb. de 2017
Did you try my panels method? It should, and would if you'd just try it.
Or did you try to use
cla reset;
before plotting to get rid of remnants? Or, if you like doing things the hardest way, just delete the handles to the existing plots and create 4 brand new ones.
Pappu Murthy
Pappu Murthy el 13 de Feb. de 2017
I am out of country now without my matlab. Will try when i get back. The problem is however, i did nt get your solution. Your references to mypicture did not quite match. And that is major confusion which is why i tried to explain my situation one more time.
Image Analyst
Image Analyst el 13 de Feb. de 2017
I did not reference any variable or control called "mypicture". You use GUIDE and put two panels on it. I called them panelFour and panelOne but you can call them whatever you want. Reference them with the names that you actually used.
In one panel, place one axes. In the other panel, place 4 axes.
Then just set the visibility property of the two panels to show one and hide the other.

Iniciar sesión para comentar.

Preguntada:

el 10 de Feb. de 2017

Comentada:

el 4 de Mzo. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by