Multiple axes in GUI

  • Permalink
  • submit to reddit
  • Email
  • Follow


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
Reply Rasmus 1/7/2010 6:56:22 PM

See related articles to this posting


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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply Andy 1/7/2010 9:51:02 PM

It's all very true
Thanks again
0
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply spommier (1) 6/15/2011 12:27:05 PM
comp.soft-sys.matlab 202915 articles. 523 followers. Post

20 Replies
2020 Views

Similar Articles

[PageSpeed] 2


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Multiple y-/x-axes within one GUI axes.
I would like to plot several axes-objects and use different y- and x-axes's within one parent axes in a GUI. This could normally be done by the plotyy-function or by low-level axes/get/set-functions. Unfortunately neither of these approaches seems to work within a GUI figure. Any ideas? In other words; Do Matlab GUI support plotting with multiple y/x-axes's within one axes? Regards Jo Arve Repp wrote: > > > I would like to plot several axes-objects and use different y- and > x-axes's within one parent axes in a GUI. This could normally be > done > by the plotyy...

GUI with multiple axes
I have two axes objects in my gui, handles.Plot1 and handles.Plot2. I need to know how to switch back and forth between these to add various features and overlays as my code progresses. I tried both axes(handles.Plot1) set(figureName,'CurrentAxes',handles.Plot1) but i receive the errors: ??? Error using ==> axes Invalid axes handle ??? Error using ==> set hggroup handle passed to 'CurrentAxes' property - valid axes handle required I've checked the handle tags several times and i am driving myself crazy! thanks Dustin wrote: > I have two axe...

Multiple Axes GUI
Hello All, I'm having a problem to design my GUI. I have a GUI that has just one axes, to show a plot depending on the various inputs. To make it look better I've put another axes, to load a image file there, but since I made this change my GUI is not working properly. When I press the button "plot", the graph appears in the wrong axes (of the image). First, I put this code before plotting what I want: >> axes(handles.axes); It plots just one time, when I try to plot again it show me this error: >> ??? Reference to non-existent field 'axes'. >>...

GUI Multiple Axes
Can somebody show me or tell me how to make a simple GUI with one pushbutton that plots in one axes and another pushbutton that plot on another axes, all on the same figure. I am trying to use axes(handles.axes1) but it doesn�t work. Do I have to do something special with the axes??? Thanks. set(gcf,'CurrentAxes',handles.Axes_1); plot(data,'b'); set(gcf,'CurrentAxes',handles.Axes_2); plot(data,'r'); "Martin" <funkiboy25@hotmail.com> wrote in message news:eecb8b5.-1@webx.raydaftYaTP... > Can somebody show me or tell me how to make a s...

Problem on a GUI with multiple axes
Hi! I'm having a problem using Matlab. I want to make a GUI that can load several images (one after another, user chosen, to display on several axes on the same GUI). If I use this (on a m file called ax.m): %Read DICOM file I = dicomread('hsj.dic'); %Get frame 60 to variable F F=I(:,:,:,60); %Define axes to use as the axes with tag axes1 axes1=findobj(ax,'tag','axes1'); %Get axes to run with axes1 axes(axes1) %Show F in axes imshow(F, []); ------------------------------ I get this error: ??? Error using ==> axes Invalid object handle. Error in ==> ax>pus...

GUI multiple axes, imagesc
Hello, My GUI has 2 axes, both need to use imagesc to display different images. How do you assign one set of images to one of the axes, and one to the other? I am not using GUIDE. Thanks "James " <jamesmccurley@csufresno.edu> wrote in message <h38jka$spn$1@fred.mathworks.com>... > Hello, > > My GUI has 2 axes, both need to use imagesc to display different images. How do you assign one set of images to one of the axes, and one to the other? I am not using GUIDE. > > Thanks imagesc(peaks(40),'Parent',yourGUIaxehandle) Put your yourGUIaxehandl...

Multiple Legends in GUI Axes
Hello! I posted earlier about getting multiple legends. I cleaned up my code a little bit, and am starting to understand my error (but still haven't solved my problem). Again, my issue is trying to generate multiple legends for the same plot in a GUI. I collected data during a test from multiple data channels over a series of runs. For my current problem, I'm trying to plot channels 1, 2, and 3 for runs 1 and 2. I can plot the data and generate a single legend for Run1, but I can't generate a separate legend for Run2. Here is the "cleaned-up" code: % RunNumberPl...

Clear multiple axes at once in a GUI
Hello, I have a GUI plotting multiple axes which all overlay one another to look like one plot on a GUI. I have a "CLEAR" button which I want to clear ALL of the axes and ALL legends inherent to those axes. The axes are referred to as members of an array: handles.data_axes(1) handles.data_axes(2) handles.data_axes(3) handles.data_axes(4) ... and so on. The legends are referred to similarly. The callback for my CLEAR button is: cla(handles.data_axes); legend(handles.data_axes,'off') set(handles.Channel2AnalyzeList,'String',[]) Currently, ...

Multiple Y-axes in GUI
hi.... I am trying to plot mutiple y-axes in GUI.... I could use plotyy.... but I jus want to draw using line...so that I had tried to create a graph using Mutiple Y-axis using Same X-axis... Here is my code... x1 = [0:.1:40]; y1 = 4.*cos(x1)./(x1+2); x1 = [0:.1:40]; y2 = x2.^2./x2.^3; hl1=line(x1,y1,'Color','r'); ax1=handles.axes1; ax2=axes('Position',get(ax1,'Position'),... 'XAxisLocation','bottom',... 'YAxisLocation','right',... 'Color','none',... 'YColor',...

GUI Multiple Axes #2
Can somebody show me or tell me how to make a simple GUI with one pushbutton that plots in one axes and another pushbutton that plot on another axes, all on the same figure. I am trying to use axes(handles.axes1) but it doesn�t work. Do I have to do something special with the axes??? Thanks. Martin wrote: > > > Can somebody show me or tell me how to make a simple GUI with one > pushbutton that plots in one axes and another pushbutton that plot > on > another axes, all on the same figure. > I am trying to use axes(handles.axes1) but it doesn�t work. Do I > have ...

multiple axes in gui #2
hello, i am very much new to matlab, i have problem with my gui..i.e. i have two axes in a single gui ,and i have a pop up menu which is used for channel extraction..i.e R G B...i planned it to work like this..axes1 will be loaded with my original image ,then when i click on popupmenu red option i want the red channel extraction do be done on the original image(axes1) and i want the output of it to be displayed in axes2 ..please tell me how can i do this.please please please please ...

GUI with multiple axes #2
Hi everybody!!! I would need a little help please! I have got a GUI with two axes but I don't know how to address them (I mean...using the firts one or the second one). My gui is only a .fig file, so I can't use the command axes(handles.axes1). Can anyone help me? Thank you!!! Max ...

Multiple y-axes in GUI plot
I would like to populate a single axes in a GUIDE-created gui with several different data sets and two y-axes (the x-axes should be identical). I need to handle an arbitrary number of data sets, but only two y-axes (so plotyy won't work). I've seen some user-submitted functions (layerplot, etc), but haven't been able to implement them successfully. In this attempt, I have a struct called tags, and tags has fields such as .data (which contains the y-data for that instance) and .axis (which has a 1 if it should be on the primary y-axis and a 0 if it should be on the secondary). The...

Multiple Line Text in GUI Axes
Something that has always bugged me that I finally though I would ask is how to get multiple lines of text in a GUI. I have instructions for an experiment, and just want to put the instructions in 1 axes. Is there any way to enter a cell or string variable as the axes' string value and do this, or do I have to manually break up each line of text in a different axes? Any help would be greatly appreciated. Bill For anyone that was interested, I guess I never tried entering then entire string variable as a cell, because I tried it and it worked. I could have sworn that I tried it befo...

Help (again) multiple Legends in GUI axes
Hello! I posted earlier about getting multiple legends. I cleaned up my code a little bit, and am starting to understand my error (but still haven't solved my problem). Again, my issue is trying to generate multiple legends for the same plot in a GUI. I collected data during a test from multiple data channels over a series of runs. For my current problem, I'm trying to plot channels 1, 2, and 3 for runs 1 and 2. I can plot the data and generate a single legend for Run1, but I can't generate a separate legend for Run2. Here is the "cleaned-up" code: % RunNumberPl...

How to draw multiple images in same axes at gui
hai everyone, I want to implement one GUI. In that gui i have one axes at some specified place. I want to show multiple images at a time on that axes. I can only show the one image at a time but i couldn't show the multiple images at a time on same axes. Please any body give suggestions. Hi!, Use subplot() command..... like subplot(2,1,1) image(imread('MyTeam.JPG')) subplot(2,1,2) image(imread('MyTeam.JPG')) Shan..... "BhupathiRao " <bhupathi_lakinana@yahoo.com> wrote in message <gtb51q$fp0$1@fred.mathworks.com>... > hai everyone, > ...

Displaying images in multiple axes in a GUI
I am trying to figure out how to display 2 images to 2 different axes in a GUI, but can't figure out how to do it. With the plot command, you can specify an axis handle, but not with imshow. I set the axes tags to "axes1" and "axes2", and try to call "axes(handles.axes1)" in the code, but then i get the following error: Error using axes Conversion to double from videoinput is not possible. Can anyone help please? Thanks On 4/15/2012 4:11 PM, Peter Russo wrote: > I am trying to figure out how to display 2 images to 2 different axes in a >GUI, but...

GUI with multiple axes and mouse input
Hi fellow matlabers, My problem is simple. I have a GUI with many axes. The user is supposed to click (single click, double, etc) on one of the axes and then a new gui opens. My problem is I dont know how to implement this user input. That is, which one of the axes did the user click on. Thanks in advance for your help wapo <apostolos1975@gmail.com> wrote in message <36c86a88-8b2f-41aa-9e06-4a9845b79a9c@r2g2000yqm.googlegroups.com>... > Hi fellow matlabers, > > My problem is simple. I have a GUI with many axes. The user is > supposed to click (single click, double, ...

Matlab GUI
hi, I have matlab 5.3. I need to create a project with GUI. There will be 2 axes. When user click the button he will be able to load an image. the image will be displayed in the 1st axis (but lways the same). The second axis will be for other purpose. Now I wrote as a callback for the button: [fname, fpath]=uigetfile('*.jpg', 'load a file'); if fname~=0 set(gcf,'CurrentAxes',findobj('Tag','Axes2')); img=imread(strcat(fpath,fname), 'jpg'); ...

Viewing live video in a GUI with multiple axes
Hello all, Yep im a newbee on here but this forum seems to be a holy grail of information for me and has been an amazing help to my university project work so far. anyway here's a quick rundown of what i've been trying to do, i have a video capture device working fine with the image acquisition tools. i have several other m-files that will be grabbing frames as required and performing some processing upon them. so my problem, i would like to have a GUI with a few controls for the processing m-files (no problems there) but i would also like 2 frames, one showing the raw video comming...

handling multiple axes in different figures in a GUI
I am trying to display the result in a different figure window than the one I am currently working on. My result is in the form of images, that I am displaying using imshow, and the filename is obtained from data in my first figure's m-file. I am having trouble with using the handles of the existing multiple axes in my second figure, so that I can display the images. while using this sort of code allows me to display the image, in a new axes, it doesnt allow me to display it on an existing axes, which is what i need to do. fig2_hndl = fig(fig2) axes_hndl = axes('Parent', fig2_hn...

modifying "GUI with Multiple Axes"
Hello I have tried to modify the example "GUI with multiple axes" page 5-2 in the Matlab document "Creating Graphical User Interfaces". I have added only some more edit text windows and when I run the fig programm I get a long error message, the top part of it is: ??? Error using ==> feval Undefined function 't_input_CreateFcn'. Error in ==> ....\toolbox\matlab\uitools\gui_mainfcn.m On line 66 ==> feval(varargin{:}); Error in ==> ..... \modified_multipleAxes.m On line 42 ==> gui_mainfcn(gui_State, varargin{:}); ??? Error using ==>...

Creating a Grid toggle button in GUI with multiple axes
Hello, I would like to create a grid toggle button in my uitoolbar. My GUI has multiple axes so the simple approach doesn't work: ie. grid_uitogglebutton_Callback(hObject,eventdata,handles) grid I want the grid toggle button to act similar to the legend button when dealing with multiple axes. The legend button seems to recognize which axes is current. Then the button changes state according to if there is a legend on the axes or not. My simple grid toggle button stays depressed even when I switch to a different axes. I did try to add an additional legend button to the uitoolbar with ...

Changing colors of multiple plots on single Axes object in a GUI
Hi all, I have a gui with a single axes object and two push buttons. When one of the buttons is clicked, its callback function does a calculation and plots the results. Then "hold on" is called so that the plot remains in the figure even if the other button is pressed. It works great, but the only problem is that it doesn't cycle through colors. I would like each new plot added to the axes to be a new color, but I am not sure how to make that happen. The code is very long, so it might not be wise to post the whole thing, but here's a sample so you might have an idea of what...