Search code examples
pythonmatplotlibfigurewindow-managers

How to tile matplotlib figures evenly on screen?


Does matplotlib offer a feature to spread multiple figures evenly on the screen? Or does anyone know of a toolbox that is able to achieve this? I'm getting tired of doing this by hand.

import matplotlib.pyplot as plt
for i in range(5):
    plt.figure()
plt.show()

This creates five figures that are staying on top of each other. To check what is on figure 1, I have to move the other 4 figures to the side.

On MacOS, I could use the Ctrl+ shortcut just to get a glimpse on all the figures. Alternatively, I could write the plots to files and inspect the images in a gallery. But I wondered if there is a custom window manager for matplotlib out there that possibly offers some more flexibility.

In Matlab, I got used to tools such as spreadfigure or autoArrangeFigures.


Solution

  • You can control the position of the plot window using the figure manager like so:

    import matplotlib.pyplot as plt
    
    start_x, start_y, dx, dy = (0, 0, 640, 550)
    for i in range(5):
        if i%3 == 0:
            x = start_x
            y = start_y  + (dy * (i//3) )
        plt.figure()
        mngr = plt.get_current_fig_manager()
        mngr.window.setGeometry(x, y, dx, dy)
        x += dx
    plt.show()
    

    This will result in five graphs shown beside each other like so: enter image description here

    Hopefully, this is what you're looking for!