Set Figure's position

Hello, Is there an easy way to set the initial position of a

    > Figure? I'm using Windows XP and new figures seem to pop up
    > in the typical Windows fashion where subsequent figures
    > appear about 20 pixels down and 20 pixels to the right of
    > previous figures. How can I tell each figure where to pop up
    > on screen?

matplotlib doesn't provide explicit support for this, but it is
possible. What backend are you using. The matplotlib Figure is
embedded in a FigureCanvas which is typically a GUI widget embedded in
a GUI Window. In the pylab interface, the canvas is managed by a
FigureManager, which has a window attribute on most of the backends.

Eg for the GTK backend, for example, you could do

    from pylab import *

    import gtk

    figure(1)
    plot([1,2,3])
    manager = get_current_fig_manager()

    # see gtk.Window class docs at
    # Overview — PyGObject
    manager.window.set_position(gtk.WIN_POS_CENTER)

    figure(2)
    plot([1,2,3])
    manager = get_current_fig_manager()

    # see gtk.Window class docs at
    # Overview — PyGObject
    manager.window.set_position(gtk.WIN_POS_NONE)

    show()

For the WX* backend, manager.window is a wxFrame -
http://www.lpthe.jussieu.fr/~zeitlin/wxWindows/docs/wxwin_wxframe.html#wxframe

For the TkAgg backend, manager.window is a Tkinter.Tk instance -
http://starship.python.net/crew/fredrik/tkclass/ClassToplevel.html

Off the top of my head I don't know the right incantation for each
backend, but hopefully the classdocs I referenced above will help.
Perhaps Todd or Matthew can chime in with more Tk and WX information.

While this arrangement may be suboptimal, we are resisting the urge to
become a GUI library. The temptations to abstract GUI functions for
use in matplotlib are many, and we are trying to keep this to a
manageable core (some event handling, some basic window management,
etc.). It's been on my list of things to do to investigate anygui,
however - http://anygui.sourceforge.net - which would appear to solve
our problems but might require a substantial refactoring of the
matplotlib backends.

If you want full GUI control, you can embed matplotlib in your own GUI
application, following one of the many embedding_in_*.py examples in
the examples subdirectory of the matplotlib src distribution.

If you come up with example code for your backend, please post it to
the list.

JDH

In TkAgg it works like this:

get_current_fig_manager().window.wm_geometry("+200+300")

To set the window position to X=200, Y=300.

Todd

···

On Wed, 2004-12-15 at 16:49 -0600, John Hunter wrote:

    > Hello, Is there an easy way to set the initial position of a
    > Figure? I'm using Windows XP and new figures seem to pop up
    > in the typical Windows fashion where subsequent figures
    > appear about 20 pixels down and 20 pixels to the right of
    > previous figures. How can I tell each figure where to pop up
    > on screen?

matplotlib doesn't provide explicit support for this, but it is
possible. What backend are you using. The matplotlib Figure is
embedded in a FigureCanvas which is typically a GUI widget embedded in
a GUI Window. In the pylab interface, the canvas is managed by a
FigureManager, which has a window attribute on most of the backends.

Eg for the GTK backend, for example, you could do

    from pylab import *

    import gtk

    figure(1)
    plot([1,2,3])
    manager = get_current_fig_manager()

    # see gtk.Window class docs at
    # Overview — PyGObject
    manager.window.set_position(gtk.WIN_POS_CENTER)

    figure(2)
    plot([1,2,3])
    manager = get_current_fig_manager()

    # see gtk.Window class docs at
    # Overview — PyGObject
    manager.window.set_position(gtk.WIN_POS_NONE)

    show()

For the WX* backend, manager.window is a wxFrame -
http://www.lpthe.jussieu.fr/~zeitlin/wxWindows/docs/wxwin_wxframe.html#wxframe

For the TkAgg backend, manager.window is a Tkinter.Tk instance -
http://starship.python.net/crew/fredrik/tkclass/ClassToplevel.html

Off the top of my head I don't know the right incantation for each
backend, but hopefully the classdocs I referenced above will help.
Perhaps Todd or Matthew can chime in with more Tk and WX information.

As is becoming usual, my attempt to upgrade has run into a problem.

WinXP,
deleted previous ...\matplotlib before installing.

None of the examples (from the new zip file) seem to run. They generally seem to start with

from pylab import *

but this fails, even from the command line. Bug, feature, or pilot error? :slight_smile:

-gary

···

----------------------------------------------------------

C:\Python23\Lib\site-packages\matplotlib\examples>python
Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pylab import *
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Python23\Lib\site-packages\pylab.py", line 1, in ?
    from matplotlib.pylab import *
  File "C:\Python23\Lib\site-packages\matplotlib\pylab.py", line 184, in ?
    from axes import Axes, PolarAxes
  File "C:\Python23\Lib\site-packages\matplotlib\axes.py", line 6, in ?
    from numerix import MLab, absolute, arange, array, asarray, ones, transpose,
\
ImportError: cannot import name min

Either first import everything from matplotlib
or do instead
from matplotlib.pylab import *

hth,
Alan Isaac

···

On Wed, 15 Dec 2004, Gary apparently wrote:

from pylab import *