Discussion:
Subplot - GUI axes
(too old to reply)
m***@gmail.com
2014-01-19 23:55:03 UTC
Permalink
Hi

I'm trying to use subplot with a single axes in a GUIDE GUI. However, every time I do it using the subplot and plot commands it turns the single axes I'd added to the GUI canvas, into a multiple axes spread out over the entire canvas. The net result is that it's impossible to place other objects on the GUI as the subplot axes goes over the top.

What am I doing wrong here?

Thanks
Steven Lord
2014-01-20 16:52:59 UTC
Permalink
Post by m***@gmail.com
Hi
I'm trying to use subplot with a single axes in a GUIDE GUI.
What do you mean?
Post by m***@gmail.com
However, every time I do it using the subplot and plot commands it turns
the single axes I'd added to the GUI canvas, into a multiple axes spread
out over the entire canvas.
Yes; that's the EXPECTED behavior of SUBPLOT.

http://www.mathworks.com/help/matlab/ref/subplot.html

"Create axes in tiled positions"
Post by m***@gmail.com
The net result is that it's impossible to place other objects on the GUI
as the subplot axes goes over the top.
What am I doing wrong here?
Explain in more detail exactly what you're trying to do and perhaps the
group can offer suggestions for how to achieve that goal.
--
Steve Lord
***@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
m***@gmail.com
2014-01-20 17:43:52 UTC
Permalink
Apologies, looking back at my original post I realise that there are some misleading statements in there!

So, I've created a simple GUI in GUIDE which has one axes object on it. Size wise the axes object has been defined to fill, let's say, half the GUI canvas.

What I want to do is issue a subplot & plot command to split the defined axes region into, let's say, 3 subplots.

When I tried this the three resulting plots were created as expected but they fill almost the entire GUI canvas instead of being restricted to the axes object dimensions. It's almost as if the subplot commands ignore the fact that I only gave it half the GUI canvas, and treats the whole thing as one figure.

Just to be clear, if my axes object is called 'axes1' I'm issuing the following (simplified) commands in the callback for a push button

For i=1:3
Subplot(3,1,i)
Plot(handles.axes1,x,y)
End

I'll try this again just to be sure I didn't make any mistakes...
m***@gmail.com
2014-01-20 20:35:09 UTC
Permalink
Searching on this forum with 'subplot gui' shows that loads of other users have come across the same problem. Subplot splits the current figure (ie the whole GUI canvas) not the current axes (ie axes1 uiobject).

The common suggestion is to create exactly number of axes you need in your GUI then send each plot command to a specific axes. This works fine when you know in advance how many plots you need. If the number of plots is defined by user input or the number of data series this is no good.

Subplot would be ideal for this but I can't see a solution. I can use subplot in a separate figure (outside the GUI) but I really need it within the GUI to allow uicontrols to control the data in the plots.

:-(
Steven Lord
2014-01-20 21:34:35 UTC
Permalink
Post by m***@gmail.com
Searching on this forum with 'subplot gui' shows that loads of other users
have come across the same problem. Subplot splits the current figure (ie
the whole GUI canvas) not the current axes (ie axes1 uiobject).
That is correct. Axes cannot be children of axes; they are children of
figures or uipanels. The axes created by SUBPLOT are no different in this
respect.
Post by m***@gmail.com
The common suggestion is to create exactly number of axes you need in your
GUI then send each plot command to a specific axes. This works fine when
you know in advance how many plots you need. If the number of plots is
defined by user input or the number of data series this is no good.
If you know an upper limit, you can mentally partition off your figure. For
example, if you know you want to support up to 6 axes and you want those
axes to cover the top half of your figure, tell SUBPLOT to create a "grid" 4
axes high and 3 wide and only use locations 1 through 6.

c = [1 0 0; 0 1 0;
0 0 1; 1 0 1;
1 1 0; 0 1 1];
for k = 1:6
ax = subplot(4, 3, k);
set(ax, 'Color', c(k, :))
end

This should create six axes: red, green, and blue in the first row and
magenta, yellow, and cyan in the second.

If you don't have an upper limit, you risk your user asking for a million
plots and your machine screeching to a half (or MATLAB throwing an error or
crashing when your machine runs out of memory to use to create the
graphics.)
Post by m***@gmail.com
Subplot would be ideal for this but I can't see a solution. I can use
subplot in a separate figure (outside the GUI) but I really need it within
the GUI to allow uicontrols to control the data in the plots.
--
Steve Lord
***@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
m***@gmail.com
2014-01-20 22:55:12 UTC
Permalink
Thanks for your reply Steven.

Would the suggestion in the following post, using a uipanel, also work (I'm not currently with a copy of matlab so can't try it)? If I understand it correctly I could define a uipanel in the gui to restrict the extent of the subplot

http://www.mathworks.co.uk/matlabcentral/answers/21988

Mark
m***@gmail.com
2014-01-21 23:15:37 UTC
Permalink
Btw, I tested it today and using a uipanel to restrict the subplot in a gui works like a charm. You have to remember to feed the uipanel handle.

I. E.

Subplot(1,1,4,'Parent',handles.panel)

Loading...