Multiple axes in GUI

Hi there,

I'm using guide to make a GUI with two axes, but I cannot assign the current figure handle to one of the two axes. It keeps plotting in just one of the axes. Any ideas how to solve this problem?
0
Rasmus
1/7/2010 6:56:22 PM
comp.soft-sys.matlab 207306 articles. 1 followers. lunamoonmoon (258) is leader. Post Follow

20 Replies
3037 Views

Similar Articles

[PageSpeed] 47
You call the axes() function to switch focus between axes, or else
just pass the axes handle in to the plotting routine that you are
using (plot(), bar(), scatter,(), etc.).  Why do you say that you
cannot do this?
0
ImageAnalyst
1/7/2010 7:07:01 PM
"Rasmus" <prof.rasmusolesen@gmail.com> wrote in message <hi5aom$rvp$1@fred.mathworks.com>...
> Hi there,
> 
> I'm using guide to make a GUI with two axes, but I cannot assign the current figure handle to one of the two axes. It keeps plotting in just one of the axes. Any ideas how to solve this problem?

I'm not sure what you mean by "assign the current figure handle to one of the two axes".  The axes have their own handles, and you can pass the axes handle as an argument to the plot command in order to specify where you are plotting:

% The figure and the axes
f=figure;
ax1=axes('parent',f,'position',[0 0 0.9 0.4]);
ax2=axes('parent',f,'position',[0 0.5 0.9 0.4]);

% Two sets of data
x1=1:100;
x2=1:100;
y1=1:100;
y2=sin(x2);

% First argument to plot controls which axes is used
plot(ax1,x1,y1);
plot(ax2,x2,y2);
0
Andy
1/7/2010 7:09:05 PM
By "assign the current figure handle to one of the two axes" I mean the following: I have made two axes in the guide tool and saved it in a .fig file. A callback function will have to plot a graph in either axes1 or axes2.

The code you have written is assigning a figure window outside the GUI figure window, so in some way I'll have to write a handle to the two axes and later get that handle in case of a callback.
0
Rasmus
1/7/2010 8:27:04 PM
Rasmus:
Simply do this:

axes(handles.axesPlot1);
plot(x1,y1);
axes(handles.axesPlot2);
plot(x2,y2);

or do this:
plot(handles.axesPlot1, x1, y1);
plot(handles.axesPlot2, x2, y2);

It will plot in the correct axes.
1
ImageAnalyst
1/7/2010 8:46:08 PM
"Rasmus" <prof.rasmusolesen@gmail.com> wrote in message <hi5g2o$q88$1@fred.mathworks.com>...
> By "assign the current figure handle to one of the two axes" I mean the following: I have made two axes in the guide tool and saved it in a .fig file. A callback function will have to plot a graph in either axes1 or axes2.
> 
> The code you have written is assigning a figure window outside the GUI figure window, so in some way I'll have to write a handle to the two axes and later get that handle in case of a callback.

But when you create a figure in GUIDE, it stores all of the handles for you in the structure names "handles".  So you already have access to the handles of your axes in any callback function in that figure.  I don't understand the problem.
0
Andy
1/7/2010 8:47:02 PM
The problem is the handle list. I assign handles to the axes in GUIDE, but when I use them in the m-file, they are not there - not even a function (Callback, CreateFcn etc.) for the axes.
0
Rasmus
1/7/2010 9:05:20 PM
The problem is the handle list. I write a handle name to the axes in GUIDE, but they are undefined in the m-file, when I try to use them. No code in the m-file even includes the axes.
0
Rasmus
1/7/2010 9:07:04 PM
Sorry for the small comments...

I got the plot(handles.axes1,x1,y1) to work, but no when I want grid in the figure, I can't just write "grid on" as usually. Is there a way to use a command like "figure(handles.axes1)" (this is not the solution) so this is always active?
0
Rasmus
1/7/2010 9:17:23 PM
On Jan 7, 1:07=A0pm, "Rasmus" <prof.rasmusole...@gmail.com> wrote:
> The problem is the handle list. I write a handle name to the axes in GUID=
E, but they are undefined in the m-file, when I try to use them. No code in=
 the m-file even includes the axes.

When you create the axes in GUIDE, they have tags, don't they?
For example, the default tag is "axes1".
To get the handle to this axes, type "handles.axes1"

Why do you expect a function to be created for an axes object?

-Nathan
0
Nathan
1/7/2010 9:20:20 PM
"Rasmus" <prof.rasmusolesen@gmail.com> wrote in message <hi5j13$8vq$1@fred.mathworks.com>...
> Sorry for the small comments...
> 
> I got the plot(handles.axes1,x1,y1) to work, but no when I want grid in the figure, I can't just write "grid on" as usually. Is there a way to use a command like "figure(handles.axes1)" (this is not the solution) so this is always active?

I think it will be clearer to use the function form of commands like grid.  The grid function can take the axes handle as an argument, so if you want a grid on axes1, you can type:

grid(handles.axes1);
0
Andy
1/7/2010 9:23:04 PM
On Jan 7, 4:17=A0pm, "Rasmus" <prof.rasmusole...@gmail.com> wrote:
> Sorry for the small comments...
>
> I got the plot(handles.axes1,x1,y1) to work, but no when I want grid in t=
he figure, I can't just write "grid on" as usually. Is there a way to use a=
 command like "figure(handles.axes1)" (this is not the solution) so this is=
 always active?

-------------------------------------------------
Yes you can - I did it just earlier today.  Maybe you can try the
functional form of it (with the parentheses) like Andy suggested.  The
grid function will operate on whatever the current axes is (the "gca").
0
ImageAnalyst
1/7/2010 9:29:00 PM
Okay, got it to work now with the function form. So there are no easy way of saying that I want to use this axes now, and then do all the plotting and move on with the next axes? I'll just use the handle in every command then.

Thanks for the replies
0
Rasmus
1/7/2010 9:34:05 PM
"Rasmus" <prof.rasmusolesen@gmail.com> wrote in message <hi5k0d$d7n$1@fred.mathworks.com>...
> Okay, got it to work now with the function form. So there are no easy way of saying that I want to use this axes now, and then do all the plotting and move on with the next axes? I'll just use the handle in every command then.
> 
> Thanks for the replies

You can do this.  ImageAnalyst showed you how.  Here is a modified form of my original script:

% The figure and the axes
f=figure;
ax1=axes('parent',f,'position',[0 0 0.9 0.4]);
ax2=axes('parent',f,'position',[0 0.5 0.9 0.4]);

% Two sets of data
x1=1:100;
x2=1:100;
y1=1:100;
y2=sin(x2);

% First argument to plot controls which axes is used
plot(ax1,x1,y1);
plot(ax2,x2,y2);

% Now give control ax1
axes(ax1);
grid on; % only turns on the grid for ax1
hold on; % only turns on hold for ax1
plot(1:100,100*rand(1,100)); % this plots to ax1, since ax1 is the current axes
plot(ax2,1:100,100*rand(1,100)); % this plots to ax2, but overwrites the earlier plot
% the hold on only applied to ax1.




Since using commands like:

grid on;
hold on;

in your code may have unintended consequences (for example, if the current axes unexpectedly changes), I recommend sticking with the functional forms and always specifying the appropriate axes.  It costs only a little time while coding, and it improves both reliability of the code and readability of the code.
0
Andy
1/7/2010 9:51:02 PM
It's all very true
Thanks again
0
Rasmus
1/7/2010 10:03:06 PM
Hi,
I have a similar problem. 
I have a GUI with more axes, I work in an external m file using the handle of the GUI.
What I would like to do is something like :

text(gui_handle.axes1,0,0,'hello world');

but text command doesn't take axes as params, so what i do is the following:

axes(gui_handle.axes1);
text(0,0,'hello world');

but instead of printing in axes1, it open up a new figure1 and plot the text there.

Any ideas?
0
Andrea
4/3/2010 6:57:05 PM
"Andrea " <andrea.alessandre...@gmail.com>

Try this:

axes(gui_handle.axes1);
gui_handle.axes1
gca

See if they both put out exactly the same number to the command
window.  If they don't, you didn't switch axes for some reason.  Maybe
you can try setappdata() and getappdata().

0
ImageAnalyst
4/3/2010 7:21:01 PM
You are right, the numbers are different.

Can you give me an example o how to use setappdata() and getappdata() to solve this problem. I couldn't find it on the mathworks help.
0
Andrea
4/3/2010 9:25:24 PM
On Apr 3, 5:25=A0pm, "Andrea " <andrea.alessandre...@gmail.com> wrote:
> You are right, the numbers are different.
>
> Can you give me an example o how to use setappdata() and getappdata() to =
solve this problem. I couldn't find it on the mathworks help.

-------------------------------------------------------------
You're right that there's no examples in the help for those functions,
but look up "application data" in the R2010a help and there is an
example with explanation there.
0
ImageAnalyst
4/4/2010 1:30:37 AM
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <a90b730f-6bcd-47d9-847a-c0279bb0e183@r1g2000yqb.googlegroups.com>...
> On Apr 3, 5:25 pm, "Andrea " <andrea.alessandre...@gmail.com> wrote:
> > You are right, the numbers are different.
> >
> > Can you give me an example o how to use setappdata() and getappdata() to solve this problem. I couldn't find it on the mathworks help.
> 
> -------------------------------------------------------------
> You're right that there's no examples in the help for those functions,
> but look up "application data" in the R2010a help and there is an
> example with explanation there.


I encountered a similar issue, but slightly complicated by the detail of trying to populate the axes with an initial plot. I noticed that the structure member for the axis was deleted after invoking the CreateFcn for that axis (why?). The simple fix was to add the following lines at the end of the CreateFcn for each axis I was populating on startup of the gui:


function axesX_CreateFcn(hObject, eventdata, handles)
imshow('../myimage.jpg');           % initial image I want to display
handles.axesX=hObject;              % tag for this axis, which I call axesX in this example
guidata(hObject, handles);           % update the handles structure for the gui

Thanks to the above thread for pointing me in the right direction. I have yet to see if my addition is redundant, so please forgive the extra text if it is.

Later,
Stephen
0
Stephen
1/12/2011 5:20:07 AM
"Stephen" wrote in message <igjdm7$4jj$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <a90b730f-6bcd-47d9-847a-c0279bb0e183@r1g2000yqb.googlegroups.com>...
> > On Apr 3, 5:25 pm, "Andrea " <andrea.alessandre...@gmail.com> wrote:
> > > You are right, the numbers are different.
> > >
> > > Can you give me an example o how to use setappdata() and getappdata() to solve this problem. I couldn't find it on the mathworks help.
> > 
> > -------------------------------------------------------------
> > You're right that there's no examples in the help for those functions,
> > but look up "application data" in the R2010a help and there is an
> > example with explanation there.
> 
> 
> I encountered a similar issue, but slightly complicated by the detail of trying to populate the axes with an initial plot. I noticed that the structure member for the axis was deleted after invoking the CreateFcn for that axis (why?). The simple fix was to add the following lines at the end of the CreateFcn for each axis I was populating on startup of the gui:
> 
> 
> function axesX_CreateFcn(hObject, eventdata, handles)
> imshow('../myimage.jpg');           % initial image I want to display
> handles.axesX=hObject;              % tag for this axis, which I call axesX in this example
> guidata(hObject, handles);           % update the handles structure for the gui
> 
> Thanks to the above thread for pointing me in the right direction. I have yet to see if my addition is redundant, so please forgive the extra text if it is.
> 
> Later,
> Stephen

Same issue for me with the handles of axes that curiously vanished after being created. Stephen's idea of forcing the gui structure handles to be refreshed does work. I don't know why, but thanks anyway ...
Sébastien
0
spommier (1)
6/15/2011 12:27:05 PM
Reply:
Similar Artilces: