Menu

gcf() does not return selected figure

Help
2005-09-28
2013-04-25
  • Nobody/Anonymous

    gcf() returns the handle to the most recent created figure, and NOT the figure that has focus. For example:
    figure; plot(sin(0:0.1:2*pi), 'b-'); title('First created');
    figure; plot(cos(0:0.1:2*pi), 'r-'); title('second created');
    figure; plot(abs(sin(0:0.1:2*pi)), 'r-'); title('third created');
    get(gcf(),'Number')

    returns '3' - ok
    But now selecting figure 1 with the mouse, dragging it somewhere and issuing
    get(gcf(),'Number')
    returns still '3'

    A consequence is, that you can only plot into the most recent figure, not into any previously created ones.

    You have to manually set the 'CurrentFigure' root property. e.g.
    set(0,'CurrentFigure', 1);
    get(gcf(),'Number')
    returns now '1', and also consecutive plot commands are printed in figure #1 now.

    I don't know if this is by design or a bug.

     
    • Shai Ayal

      Shai Ayal - 2005-09-28

      you are right.

      an easier way to select make figure N the current figure is to use the figure command:

      fingure(N);

      makes fingure N the current figure, creating it if it does not yet exist. This is Matlab compatible I think.

      Selecting the current figure (and also the current axes) using the mouse is supported in matlab, and is on my todo list.

      Shai

       
    • Nobody/Anonymous

      ah, stupid me.
      I could have thought about calling
      figure(N);
      which is the way it is done in MATLAB - you are right.

      I stumbled over it, because issuing a print() command did not print the active figure, but the current figure, and calling now
      figure(N);
      print(...);
      works perfectly - thanks to the 'Position' patch.

      thanks for the hint & patch - keep on going!

      ben

       
    • Tormod Volden

      Tormod Volden - 2006-10-04

      > makes fingure N the current figure, creating it if it does not yet exist. This is Matlab compatible I think.

      It looks like it is not created if it does not yet exist. I just filed a Feature Request on this.

      BTW, what is the 'Position' patch?

      Thanks,
      Tormod

       
    • Tormod Volden

      Tormod Volden - 2006-10-04

      WRT the 'Position' patch, never mind, I found it under "Patches" (duh).

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.