Is it possible to set the absolute position of a figure on the screen using matplotlib with the MacOSX backend?
This answer
How do you set the absolute position of figure windows with matplotlib?
says it can be done for other backends, but doesn't mention how to do it with the MacOSX backend.
With the MacOSX backend there is no way to set the window position of a matplotlib window. However under MacOSX generally speaking you can use other matplotlib backends which allow for this. The TkAgg
backend (using Tcl/Tk
via the Tkinter binding in the Python standard library) should be installed automatically.
In your python script, before anything else, switch to this backend, then create your plot, show it and now you can move the window with
get_current_fig_manager().window.wm_geometry("+<x-pos>+<y-pos>")
Here a working example:
import matplotlib
matplotlib.use("TkAgg") # set the backend
import matplotlib.pyplot as plt
plt.figure()
plt.plot([0,1,2,0,1,2]) # draw something
plt.show(block=False)
plt.get_current_fig_manager().window.wm_geometry("+600+400") # move the window
If you install the IMHO nicer Qt4 GUI framework with the PyQt bindings, then you position the window with
get_current_fig_manager().window.setGeometry(<x-pos>,<x-pos>,<width>,<height>)
Again the full example:
import matplotlib
matplotlib.use("Qt4Agg") # set the backend
import matplotlib.pyplot as plt
plt.figure()
plt.plot([0,1,2,0,1,2]) # draw something
plt.show(block=False)
plt.get_current_fig_manager().window.setGeometry(600,400,1000,800)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With