matplotlib window layout questions

后端 未结 2 869

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 maximiz

相关标签:
2条回答
  • 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
    
    0 讨论(0)
  • 2021-02-14 02:21

    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)
    
    0 讨论(0)
提交回复
热议问题