12

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.

joaquin
  • 82,968
  • 29
  • 138
  • 152
Gökhan Sever
  • 8,004
  • 13
  • 36
  • 38
  • I'm sorry maybe I am the only one who does not understand your second question. What do you actually mean when you say that the mpl window **tend** to open on your **small screen**? – joaquin Oct 19 '11 at 01:12
  • Hi, It is a setup similar to what is shown in this image: http://www.flickr.com/photos/naudinsylvain/4138134276/in/set-72157621564878435 So, when I run mpl plot creating scripts, I want these windows to always open on the big (second) screen. Is this clearer now? – Gökhan Sever Oct 19 '11 at 02:33
  • For the first question, see https://stackoverflow.com/questions/12439588/how-to-maximize-a-plt-show-window-using-python. – HelloGoodbye Sep 26 '17 at 11:37

2 Answers2

7

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
leifdenby
  • 1,428
  • 1
  • 13
  • 10
5

Relative to your first question, you can use Maximize on your figure manager (as your figure manager is a FigureManagerWx instance) or equivalent methods in case of other backends:

>>> from matplotlib import pyplot as plt
>>> plt.plot([1,2,6,4])
[<matplotlib.lines.Line2D object at 0x0000000008E5D2E8>]
>>> mng = plt.get_current_fig_manager()
>>> plt.show()                                    # you get normal size
>>> mng.frame.Maximize(True)                      # now mpl window maximizes

For the second question, I am not sure (i can not test it) but if the problem can be solved by setting the position of your figure in a screen extended in two monitors, then you can use SetPosition (again for a wxAgg backend):

>>> mng.frame.SetPosition(*args, **kwargs)
joaquin
  • 82,968
  • 29
  • 138
  • 152
  • Thanks joaquin. The first solution is exactly what I am looking for. Do you know what's the Qt4 equivalent to get maximized plots? I will test the dual-monitor answer and report back tomorrow. – Gökhan Sever Oct 20 '11 at 02:33
  • showMaximized() doesn't have any effect on the figure size. I think the right solution includes mng.canvas.setWindowState(param), but I am not sure what exactly to pass for param here. – Gökhan Sever Oct 21 '11 at 00:06
  • SetPosition((x point in the second monitor, y (a value)) ensures that the window is positioned in the second screen. I use a call like SetPosition((1400, 500)) which works as I was expecting. – Gökhan Sever Oct 21 '11 at 00:13
  • @Gökhan Sever, then you should accept my answer. This will also increase your acceptation rate... ;-) – joaquin Oct 21 '11 at 04:54