How do you set the absolute position of figure windows with matplotlib?

FINALLY found the solution for QT backend:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
mngr = plt.get_current_fig_manager()
# to put it into the upper left corner for example:
mngr.window.setGeometry(50,100,640, 545)

If one doesn't know the x- and y-width one can read them out first, like so:

# get the QTCore PyRect object
geom = mngr.window.geometry()
x,y,dx,dy = geom.getRect()

and then set the new position with the same size:

mngr.window.setGeometry(newX, newY, dx, dy)

I was searching quite often for this and finally invested the 30 minutes to find this out. Hope that helps someone.


For Qt4Agg, this worked for me.

fig = figure()
fig.canvas.manager.window.move(0,0)

Tested on Win7, mpl version 1.4.2, python 2.7.5


With help from the answers thus far and some tinkering on my own, here's a solution that checks for the current backend and uses the correct syntax.

import matplotlib
import matplotlib.pyplot as plt

def move_figure(f, x, y):
    """Move figure's upper left corner to pixel (x, y)"""
    backend = matplotlib.get_backend()
    if backend == 'TkAgg':
        f.canvas.manager.window.wm_geometry("+%d+%d" % (x, y))
    elif backend == 'WXAgg':
        f.canvas.manager.window.SetPosition((x, y))
    else:
        # This works for QT and GTK
        # You can also use window.setGeometry
        f.canvas.manager.window.move(x, y)

f, ax = plt.subplots()
move_figure(f, 500, 500)
plt.show()

there is not that I know a backend-agnostic way to do this, but definitely it is possible to do it for some common backends, e.g., WX, tkagg etc.

import matplotlib
matplotlib.use("wx")
from pylab import *
figure(1)
plot([1,2,3,4,5])
thismanager = get_current_fig_manager()
thismanager.window.SetPosition((500, 0))
show()

per @tim at the comment section below, you might wanna switch to

thismanager.window.wm_geometry("+500+0")

instead. For TkAgg, just change it to

thismanager.window.wm_geometry("+500+0")

So I think you can exhaust through all the backends that are capable of doing this, if imposing a certain one is not an option.