Plot to a specific figure

  • Permalink
  • submit to reddit
  • Email
  • Follow


I activate and get the handle to a specific figure by

h=figure(2);

and plot to it using

for tt = 0:1:T
    plot(U(tt+1,:),'o'); axis(xs);
    title(sprintf([txt ', t=%d (of %d)'], tt, T), ...
        'fontweight','b','FontSize',12);
    xlabel(strXlbl,'fontweight','b');
    ylabel(strYlbl,'fontweight','b');
    drawnow;
end

But if I click on figure 1, Matlab starts plotting to that figure and I lose what's there. How do I force plotting to a figure even if user clicks on another? It's not in documentation for plot or figure command.
0
Reply spREMOVEHITSjeffAT (67) 7/10/2013 6:16:07 PM

See related articles to this posting


On 7/10/2013 1:16 PM, Jeff wrote:
> I activate and get the handle to a specific figure by
>
> h=figure(2);
>
> and plot to it using
>
> for tt = 0:1:T
>   plot(U(tt+1,:),'o'); axis(xs);
>   title(sprintf([txt ', t=%d (of %d)'], tt, T), ...
>                      'fontweight','b','FontSize',12);
>   xlabel(strXlbl,'fontweight','b');
>   ylabel(strYlbl,'fontweight','b');
>   drawnow;
> end
>
> But if I click on figure 1, Matlab starts plotting to that figure and I
> lose what's there. How do I force plotting to a figure even if user
> clicks on another? It's not in documentation for plot or figure command.

Au contraire... :)

 >> help figure
  figure Create figure window.
     figure, by itself, creates a new figure window, and returns
     its handle.

     figure(H) makes H the current figure, forces it to become visible,
     and raises it above all other figures on the screen.  If Figure H
     does not exist, and H is an integer, a new figure is created with
     handle H.
     ...

Once you've got the handle, use it as the second form to make it the 
current figure.  To be effective if you have more than one that you want 
to use at a time then you need the handle variable to be a vector of 
handles and you must select the correct one for the desired target.

You can retrieve the current figure w/ gcf and compare to the desired; 
if not the same execute the figure(h(index_desired)) before the plotting 
commences in the function.  Or if the figure is known to be a specific 
one for the function, just hard code it in--if it exists it will make it 
current; if it doesn't it'll create a new one and make _it_ current...


--
0
Reply none1568 (7455) 7/10/2013 6:32:14 PM


"Jeff " <spREMOVEHITSjeffAT@SIGNoptonline.net> wrote in message 
news:krk8d7$79h$1@newscl01ah.mathworks.com...
> I activate and get the handle to a specific figure by
>
> h=figure(2);
>
> and plot to it using
>
> for tt = 0:1:T
>    plot(U(tt+1,:),'o'); axis(xs);
>    title(sprintf([txt ', t=%d (of %d)'], tt, T), ...
>        'fontweight','b','FontSize',12);
>    xlabel(strXlbl,'fontweight','b');
>    ylabel(strYlbl,'fontweight','b');
>    drawnow;
> end
>
> But if I click on figure 1, Matlab starts plotting to that figure and I 
> lose what's there. How do I force plotting to a figure even if user clicks 
> on another? It's not in documentation for plot or figure command.

If you have a handle to the _axes_ on figure 2, use that.

% Create two axes and store their handles
ax1 = subplot(2, 2, 1);
ax2 = subplot(2, 2, 4);

% make the lower-right corner axes "active"
axes(ax2)

% plot into upper-left axes
plot(ax1, 1:10, 1:10)

% lower-right axes is still "active"
isLowerRightActive = isequal(gca, ax2)

% As we can see by plotting into it
plot(0:0.1:2*pi, sin(0:0.1:2*pi))

Specifying the figure is not sufficient, since there may be (and in my 
example there are) multiple axes on the figure. PLOT, TITLE, XLABEL, and 
YLABEL each allow you to specify the axes handle as the first input to plot 
into or manipulate that specific axes.

-- 
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com 

0
Reply slord (13688) 7/10/2013 8:27:55 PM

dpb <none@non.net> wrote in message <krk9bb$4hc$1@speranza.aioe.org>...
> On 7/10/2013 1:16 PM, Jeff wrote:
> > I activate and get the handle to a specific figure by
> >
> > h=figure(2);
> >
> > and plot to it using
> >
> > for tt = 0:1:T
> >   plot(U(tt+1,:),'o'); axis(xs);
> >   title(sprintf([txt ', t=%d (of %d)'], tt, T), ...
> >                      'fontweight','b','FontSize',12);
> >   xlabel(strXlbl,'fontweight','b');
> >   ylabel(strYlbl,'fontweight','b');
> >   drawnow;
> > end
> >
> > But if I click on figure 1, Matlab starts plotting to that figure and I
> > lose what's there. How do I force plotting to a figure even if user
> > clicks on another? It's not in documentation for plot or figure command.
> 
> Au contraire... :)
> 
>  >> help figure
>   figure Create figure window.
>      figure, by itself, creates a new figure window, and returns
>      its handle.
> 
>      figure(H) makes H the current figure, forces it to become visible,
>      and raises it above all other figures on the screen.  If Figure H
>      does not exist, and H is an integer, a new figure is created with
>      handle H.
>      ...
> 
> Once you've got the handle, use it as the second form to make it the 
> current figure.  To be effective if you have more than one that you want 
> to use at a time then you need the handle variable to be a vector of 
> handles and you must select the correct one for the desired target.
> 
> You can retrieve the current figure w/ gcf and compare to the desired; 
> if not the same execute the figure(h(index_desired)) before the plotting 
> commences in the function.  Or if the figure is known to be a specific 
> one for the function, just hard code it in--if it exists it will make it 
> current; if it doesn't it'll create a new one and make _it_ current...
> 
> 
> --

But that keeps bringing figure 2 back to the top. I guess I wanted a way to plot to figure 2 even while it stays in the background (my question was not clear).
0
Reply spREMOVEHITSjeffAT (67) 7/10/2013 8:45:13 PM

On 7/10/2013 3:45 PM, Jeff wrote:
....

> But that keeps bringing figure 2 back to the top. I guess I wanted a way
> to plot to figure 2 even while it stays in the background (my question
> was not clear).

Ah...the transparent glistening orb was silent on that point! :)  I 
presumed it would be that you would want the one being updated to be 
current and on top.

As Steven says, you then need more granularity -- keep the axes handles 
(and you'll have to keep them straight as to which are on which figure) 
and use them to plot directly to the desired one.

--
0
Reply none1568 (7455) 7/10/2013 9:14:31 PM

dpb <none@non.net> wrote in message <krkirk$vav$1@speranza.aioe.org>...
> On 7/10/2013 3:45 PM, Jeff wrote:
> ...
> 
> > But that keeps bringing figure 2 back to the top. I guess I wanted a way
> > to plot to figure 2 even while it stays in the background (my question
> > was not clear).
> 
> Ah...the transparent glistening orb was silent on that point! :)  I 
> presumed it would be that you would want the one being updated to be 
> current and on top.
> 
> As Steven says, you then need more granularity -- keep the axes handles 
> (and you'll have to keep them straight as to which are on which figure) 
> and use them to plot directly to the desired one.
> 
> --
Thanks. I hadn't seen Steven's reply when I replied.
0
Reply spREMOVEHITSjeffAT (67) 7/11/2013 1:06:07 AM
comp.soft-sys.matlab 202902 articles. 523 followers. Post

5 Replies
107 Views

Similar Articles

[PageSpeed] 54


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Plot on Specific figure
Hello, I have data generating in loop, while within the loop there are as many as 4 figures comes to display for user selection. Every time when the loop reach to end all the windows close except two. The question is I want to subplot the generating data on the one of the two already open figure specific figure, how can I do it. I have tried following, but not sucessful. Please suggest. if p==1, figure('name','sb'),subplot(2,5,p);plot(x(:,1),x(:,2),'bo');title(['CP # ',num2str(p)]); else findobj('name','sb'),subplot(2,5,p);plot(x(:,1),x(:...

Creating a plot with line plot and scatter plot in the same figure
Hello, I am looking to plot a line plot of a function (say, x^2) and a scatter plot of various data points on the same figure. Is there a way to do this? Perhaps it involves using the "hold on" command? Thanks so much for your time! Andrew "Andrew " <rearwindow1954@yahoo.com> wrote in message <g6d0vs$kfq$1@fred.mathworks.com>... > > Perhaps it involves using the "hold on" command? > Likely yes. Bruno ...

plot a figure in a specified figures..!!
Hello, everyone... there are four axes objects, but I want to use a specfied axes object, how can I do..?? thanks.. curious wrote: > > > Hello, everyone... > > there are four axes objects, but I want to use a specfied axes > object, how can I do..?? > > thanks.. Hi, You can use the axes function to set the current axis. You didn't tell us how you are choosing the specified axes you want to use, so I can't really help much more... An example: figure h(1)=subplot(2,1,1);plot(1:10) h(2)=subplot(2,1,2);plot(2:6) axes(h(1)) title('This ...

How to save a specific plot as image and then use that image to plot into 3d plot.
I would like to know if there is any way to plot image (jpeg,tiff,bmp) on axis plot. I am currently doing a 3D volume (6 surfaces) plotting function which involves very large data set (more than 100MB worth of file size). The data will create 6 surfaces; top,bottom,left,right,front,back. While I can load the volume cube (using surf), rotating or zooming in/out really slows down/sometimes hangs the graph. I understand it happens because of the amount of data it needs to process over every rotation. My question is, are there any way to save each of the surfaces as images. This is so I can repl...

how to plot a curve in a figure to a different figure
I have two curves, one in a figure. I would like plot them together in one figure. How is this achieved conveniently? Thanks. Frank. Frank Song wrote: > > > I have two curves, one in a figure. I would like plot them together > in one figure. How is this achieved conveniently? Thanks. Frank. plot(x1,y1) hold on plot(x2,y2) Ted Frank Song wrote: > > > I have two curves, one in a figure. I would like plot them together > in one figure. How is this achieved conveniently? Thanks. Frank. You can also do this ... plot(x1,y1, x2,y2) irrespective of the size of 1st and 2nd...

Difference between plot in figure and plot in GUI?
Hi world!! I have programmed a code that plots the earth and then plots the orbit of a satellite by using a text of x,y,z coordinates. The code of the earth is programmed by the command "sphere" and then with the "surface" i give a "texturemap" with the "topo" cdata. When i run it from command window is made a figure where plotted small lines, which is the orbit's curve, and the plot is completed in about 30 seconds. I've made a GUI so that will be plotted, instead of a figure, in the GUI's environment.Now the strange thing is that the code...

how to plot 10 figures in one figure
Hi, I want to draw 10 figures in one figure and would be grateful if any one please guide me through or write a piece of code here. I want to have 10 subplots in one figure. Thanks On May 15, 10:40 am, subzazar <baarish_bar...@hotmail.com> wrote: > Hi, > > I want to draw 10 figures in one figure and would be grateful if any one please guide me through or write a piece of code here. I want to have 10 subplots in one figure. > > Thanks Your expectations are too high. No one in their right mind at CSSM is gonna "write a piece of code" for you. Have you thought ...

how to overlay a plot over another plot in a different figure
I am new to MATLAB so this may be fairly basic. I generated several plots in different figures. I want to overlay a plot from one figure that has it's own axes on top of a second plot from another figure? I know that I am suppose to use the "hold on" command, but I know I am missing many other steps. I understand that it has to do with "handles" or something. Please offer some suggestions/advice. Vinh Vuong Well i dont know if it will solve your problem but if you have 3 sets of data, let's say: x1,y1 x2,y2 and x3,y3 You can do: figure,plot(x1,y1,x2,y2,x3,y3) Ma...

plot:write text on a figure, then the figure is covered, why?
When I plot and write text on a figure, the figure where after the text (eg. grid or frame axis) is vanished, why? How to solve this problem? Thanks very much. ...

Plot 2D figures with one 3D plot
I am not sure how to properly do this. I have several Fourier Transform 2d plots that I want to be able to show in 3D with essentially just the 2d plots stacked on top of each other. Now what I have done thus far is take Fourier Transforms of some data I have in MATLAB and I have created a 262143 x 20 matrix, where each column represents a different Fourier Transform. Now to plot this data in 2D space I would do NValues=(1:262143)'; figure, plot(NValues,FTransform(:,1)); So in 3D I was thinking to do X=ones(262143,20); for ii=1:20 X(:,ii)=NValues; end and then this...

overall figure title in mult-plot figures
Say you have a figure that has 6 subplots in a 3X2 configuration, each with their own title. Now you want to put a title on the whole figure, in the center, above the titles of the top 2 subplots, but slightly below the top of the page. How can this be done without creating a text object positioned relative to one of the axes? I'm making the figures using a script and the range of the axes in each of the subplots varies. Thanks <http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=3233&objectType=file> Thanks, but the suptitle command is not recogniz...

changing color plot in a looped figure plotting
Hello, I have a question about plotting while looping to get information from an excel file I have the following script: for i=3:6:225 x=xlsread('test.xlsx','Sheet1',['B' int2str(i) ':JB' int2str(i)]); y=xlsread('test.xlsx','Sheet1',['B' int2str(i+1) ':JB' int2str(i+1)]'); plot(x,y) hold on end hold off I wish to have different color for different part of the plot. For example, it could be great that all data from 3,21,39....are plotted in green, while the one 9,27,45.... are in blue, and the data 15,33,51....a...

How can I plot many Figure to one figure?
if I have many figure with this command for 1:x figure(x); end so my figure will run out. If I want to plot figure(1) to figure (x) with unique figure as figure(x+1). What is the command of my question? On 3/28/2013 5:48 AM, chairat Kraichan wrote: > if I have many figure with this command > for 1:x > figure(x); > end > so my figure will run out. If I want to plot figure(1) to figure (x) > with unique figure as figure(x+1). > What is the command of my question? "FIGURE Create figure window. FIGURE, by itself, creates a new figure window, ...

how in gui can you plot two plots in a figure?
Hi! At Matlab as we know if we plot something, it plots it in a figure. Also if we plot something else,it plots it in the same figure by erasing the previous plot. Moreover if we write hold on , they will remain the two plots in the same window. My question is about GUI. At gui i found the way to plot, only by calling a figure in a callback of a pushbutton. If i do this it opens a figure and plot something. Moreover i want to continue a plot in the same figure with another pushbutton. But immediately it opens another figure and plots. If in this pushbutton i erase the command that opens a fig...

Labelling Figures plotted using plot function
Hi there, I wish to seek your opinion to label the figures created using the plot function. Like labelling X axes, Y axes, and main title for each figure that you display using plot function. Seeking your guidance Thanks Nishant Nishant wrote: > Hi there, > I wish to seek your opinion to label the figures created > using the plot function. > > Like labelling X axes, Y axes, and main title for each figure that you > display using plot function. > > > Seeking your guidance > > Thanks > > > Nishant > At the mat...

Multiple polar plots on same figure
I am trying to produce several polar plots on the same graph, using a loop. Each plot will have a different color.i.e. one color per iteration. However, I am having problems with the color specification. Here is what I have: for j = 1:10 . . . a=polar(x,y,color) legend(a) end Questions: a. Is there a way to specify a separate color for each iteration of the loop? b. Is there a way to display a legend showing all the colors in the figure? On 11/9/2012 7:48 PM, Stan wrote: > I am trying to produce several polar plots on the same graph, using a loop. >Eac...

How to delete a specific plot within multiple plots in a GUI?
Hi, I'm having some problems with getting a button to delete a particular plot in a GUI. I have 2 buttons - A and B. When button A is clicked, it plots 2 graphs using the code below: x = [1 2 3 4]; y1 = [2 4 6 8]; y2 = [3 6 9 12]; h1 = plot(handles.axes1,x,y1,'b'); %PLOT 1 hold on h2 = plot(handles.axes1,x,y2,'r'); %PLOT 2 Now when button B is clicked, I want PLOT 2 to be deleted. I know that "delete(h2)" doesn't work since h2 is not known within the scope of button B (i.e. it would work if I had "delete(h2)" within the code fo...

Pan/zoom a plot seperately in a multiple plot figure
Hi, what I have been trying to do for a very long time is to develop a code that would enable me to pan/zoom/control a plot seperately in a figure having multiple plots. For further clarificaiton, I have three sine wave plots in a figure with different frequences and magnitude. What I want to do is: click on one of those to select, and drag it around to any preferred location interactively, with NOT moving the other two. The existing pan command move all three together. Can anyone out there help me please? "Mohammed Islam" <mohammed_islam@oceaniccorp.com> wrote in message ...

changing color plot in a looped figure plotting #2
Hello, I have a question about plotting while looping to get information from an excel file I have the following script: for i=3:6:225 x=xlsread('test.xlsx','Sheet1',['B' int2str(i) ':JB' int2str(i)]); y=xlsread('test.xlsx','Sheet1',['B' int2str(i+1) ':JB' int2str(i+1)]'); plot(x,y) hold on end hold off I wish to have different color for different part of the plot. For example, it could be great that all data from 3,21,39....are plotted in green, while the one 9,27,45.... are in blue, and the data 15,33,51....a...

Plot: write text on a ploted figure, then the figure is covered, why?
When I plot and write text on a figure, the figure where after the text (eg. grid or frame axis) is vanished, why? How to solve this problem? Thanks very much. ...

plotting data with specific colors / plotting a single point
Hello "gnuplotters" :-) I would like to plot several data files, with specific colors. In perticular, I would like to have one plot apper in *very* light gray. How can I achieve custom colors in gnuplot, especially the light gray. Also, I'd like to plot a single point add a single plot a single point, also with a specific color and size (to make it prominent. My plan is place the commands for plotting the data as well as the single point in a script file). Thanks - Olumide In article <1175275161.134419.198490@b75g2000hsg.googlegroups.com>, Olumide <...

How to send a specific windows message to a specific figure (i.e. keypress)
The code below (matlab code) selects the proper window (in this case a mathworks matlab figure) and then throws a keypress. But the keypress (character A) goes to the matlab command console window. I would like to find a way to send the keypress to the matlab figure (opened graphic window). robot = java.awt.Robot: pos = get(FigureH, 'Position'); set(0, 'PointerLocation', [pos(1:2)]); robot.mousePress(java.awt.event.InputEvent.BUTTON1_MASK); robot.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK); java.awt.Robot.keyPress(65); Stephane ...

plot on same figure
i plot my results as plot(x); hold on; for the 1st condition. but then i change my parameters and calculate new results i run plot(x); again. when i make this for 4-5 times i couldn't understand which curve shows which condition. how can i make understandable?? i tried to make plot(x,'r') and change the curve color. but it is hard to change the color of the curve, because i must do that manually. any better suggestion please? "ben harper" <controlusc@gmail.com> wrote in message <hid9av$ic4$1@fred.mathworks.com>... > i plot my results as ...

Plot Figure
Dear All If I have vector x with 1000 entries. How I can plot the 1000 points using line whereas I want to add markers on only 10 or 20 points in one plot. Also I want to use legend which including the marker over the line. Thanks Ayman Elnashar: <SNIP wants to set special marks to a few of his/her ludicrously many dots on the canvas... one way: x=1:10000; y=x+1000*rand(size(x)); ix=1:500:x(end); line(x,y,... 'color',[1 0 0]); line(x(ix),y(ix),... 'marker','o',... 'markerfacecolor',[0 0 0],... &...