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 209327 articles. 11 followers. lunamoonmoon (258) is leader. Post Follow

20 Replies
3497 Views

Similar Articles

[PageSpeed] 21

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:

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'); ...

multiple plots in same axes of a matlab gui, (MCCabe Thiele Method for binary distillation)
Hello, I am trying to develop a GUI to find out the no of stages in a binary distillation through McCabe Thiele Method. I wish to plot more than two plots (for every loop cycle) in the same axes of my Matlab GUI. Moreover, I want none of them to be replaced by the preceding one. I tried but only the first two plots are visible. Below is the code which will make my query much clear. (Axes tag: stages) %% loop 1 for no_of_stages set(handles.stages,'NextPlot','Replacechildren') Frames=getframe; pause(1.5) title(handles.stages,'McCabe-Thiele Method - No of stages&#...

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...

Matlab GUI problem: plot in GUI axes from callback from the serial port
I build up a GUI with GUIDE in Matlab with some buttons and an axes. When I plot in the axes from button callback, then it works. But when I want to plot in the axes from a callback from the serial port (BytesAvailableFcn), then it generates a new figure and plot it inside that. I think the problem is that from the serial port callback there is the wrong current figure (I checked it with gcf during debugging), but when I try to change the current figure with figure(...) or set(..) it doesn't work. Can anyone help me? Regards Roman Janki ...

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...

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...

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'. >>...

MatLab GUI axes
1. Load in an image using uigetfile. 2. IMG = imread(FullPathName); set(gcf,'CurrentAxes',axes0); imshow(IMG); It displays the image fine in my axes I want it. But after I loaded the image again, it display the image on the next axes. Is there a way to fix this, even though I tell it to display in axes0. Thanks. "H H" <john.doe.nospam@mathworks.com> wrote in message <fhogfi$4l0$1@fred.mathworks.com>... > 1. Load in an image using uigetfile. > 2. IMG = imread(FullPathName); > set(gcf,'CurrentAxes',axes0); > imshow(IMG); > ...

Multiple panes in a Matlab GUI?
We are using Matlab to analyze/display rocket performance data. We would like to build a Matlab GUI that allows the user to view different "panes" of information by clicking on tabs at the periphery of the GUI. One pane might show plots and have a corresponding tab labeled "Graphs", whereas another pane might show textual information and be accessed by a tab labelled "Parameters". We are looking for the type of multi-pane functionality that is found in, for example, Excel or Labview. We are relatively new to Matlab GUI development and would greatly appreciate any...

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...

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 panels in gui by matlab
I have multiple buttons and I need to add panel to each button, in other words when if I press on the button, its panel will appear. The problem: I don't know how to add multiple panels to the same gui, if any know how please answer me. thanks alot Hello Ahmed, This should get you started: % Open a new figure window. This will be the panel. h = figure; % Set properties. If you want a modal window, that is, if you don't want the areas outside the window to be clickable, you should set the 'WindowStyle' property to 'modal'. set(h,'MenuBar','None',...

Circular Axes in MATLAB GUI
Hello, All. I'm currently in the process of adapting a multiple object tracking task from Psychtoolbox in MATLAB's GUI for portability reasons. However, one thing I've noticed that I'd like to fix is what happens when circles overlap. In PTB, since the circle was precisely that, the overlap was just like that of two circles. However, in MATLAB GUI, I've actually imported the circles as images into an axes and then had the axes move about the screen. As you can imagine, when the axes overlap, sometimes the corners of the of the top axes cut into the circle, and you notice th...

Multiple Plots on MATLAB GUI
Hey does anyone know how to create multiple plots on one axes in a GUI? Any suggestions or snippets would be greatly appreciated. ...

Web resources about - Multiple axes in GUI - comp.soft-sys.matlab

Code division multiple access - Wikipedia, the free encyclopedia
Code division multiple access ( CDMA ) is a channel access method used by various radio communication technologies. It should not be confused ...

Women Share How They Reach Multiple Orgasms In New Study 5
... triple) the pleasure. For some, it's just a notion and for others it's part of their sex lives, but research suggests anyone can achieve multiple ...

Instagram Officially Adds Support for Multiple Accounts
Instagram officially announced the ability for users to switch between multiple accounts. The feature had been spotted in testing for Android ...

How to add multiple Instagram accounts on your iPhone
Multiple accounts are available now in Instagram , at long last ( and officially , too). But the process of configuring more than one account ...

Ole Miss Football Reportedly Cited for Multiple Violations by NCAA
Bleacher Report Ole Miss Football Reportedly Cited for Multiple Violations by NCAA Bleacher Report The NCAA charged Ole Miss with a slew of ...

Exit polls: Donald Trump wins with multiple groups of voters - CNNPolitics.com
... with the Republican Party and the federal government, and the candidate who railed hardest on those topics, Donald Trump, won with multiple ...

Managing multiple Instagram accounts is finally a lot easier
Switching between multiple Instagram accounts is finally going to get a whole lot easier this week. Instagram has been testing a new feature ...

Facebook is testing SMS, multiple accounts in Messenger
Facebook has slowly beefed up its Messenger offering over the past year, with not only the ability to send payments and hail an Uber ride, but ...

Instagram App Now Allows Multiple Accounts. Here's How To Do It
... its most eagerly anticipated features. Much to the delight of bloggers and business users everywhere, it’s now possible to switch between multiple ...

Scientists attack Zika virus from multiple angles
Scientists attack Zika virus from multiple angles

Resources last updated: 2/14/2016 4:36:44 AM