Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib window layout questions

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.

like image 573
Gökhan Sever Avatar asked Oct 18 '11 04:10

Gökhan Sever


People also ask

How do I change the window size in Matplotlib?

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.

How do you apply tight layout?

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).

What is the difference between PLT and ax?

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.

What is fig Tight_layout ()?

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)


1 Answers

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
like image 81
leifdenby Avatar answered Oct 02 '22 01:10

leifdenby