I have two questions regarding to the positioning of a mpl window (using WXAgg backend)
1-) How to create a maximized window, instead of me clicking on window to maximize it each time?
2-) I have two screens. Interestingly, my mpl windows tend to open on my small screen. How can I force mpl/ipython/WX/X-windows to open mpl windows on my 2nd and bigger monitor?
Thanks.
Set the Height and Width of a Figure in Matplotlib These can be done either via the set() function with the figheight and figwidth argument, or via the set_figheight() and set_figwidth() functions.
Use with GridSpectight_layout method (the pyplot api pyplot. tight_layout also works). You may provide an optional rect parameter, which specifies the bounding box that the subplots will be fit inside. The coordinates must be in normalized figure coordinates and the default is (0, 0, 1, 1).
Plot − Plot helps to plot just one diagram with (x, y) coordinates. Axes − Axes help to plot one or more diagrams in the same window and sets the location of the figure.
tight_layout() method. The tight_layout() method figure module of matplotlib library is used to automatically adjust subplot parameters to give specified padding. Syntax: tight_layout(self, renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=None)
I use the Tk library for plotting, you can set this up by default in the ~/.matplotlib/matplotlibrc
file by writing:
backend : TkAgg
This allows me to set the window position and dimensions using:
import matplotlib.pyplot as plot
wm = plot.get_current_fig_manager()
wm.window.wm_geometry("800x900+50+50")
As someone might be wanting to position their matplotlib window on a Mac I wanted to make a quick contribution. I frequently work with and without an external screen (at work and at home) and wanted some way of automatically using the external screen if it is available. Luckily must of the Mac operating system can be interfaced through AppKit.
The following snippet will return a list of ScreenInfo objects with position, width and height:
from AppKit import NSScreen
class ScreenInfo:
pass
def getScreensInfo():
screens = []
for i, s in enumerate(NSScreen.screens()):
screen = ScreenInfo()
frame = s.frame()
screen.x = frame.origin.x
screen.y = frame.origin.y
screen.w = frame.size.width
screen.h = frame.size.height
screens.append(screen)
return screens
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