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.

Leave a Comment