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.

3
  • 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? Commented Oct 19, 2011 at 1:12
  • Hi, It is a setup similar to what is shown in this image: flickr.com/photos/naudinsylvain/4138134276/in/… So, when I run mpl plot creating scripts, I want these windows to always open on the big (second) screen. Is this clearer now? Commented Oct 19, 2011 at 2:33
  • For the first question, see stackoverflow.com/questions/12439588/…. Commented Sep 26, 2017 at 11:37

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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)

4 Comments

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.
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.
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, then you should accept my answer. This will also increase your acceptation rate... ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.