Steve
Steve

Reputation: 644

Matplotlib; open plots minimized?

So I've got a code that is going to make a couple plots, for which I want/have the window maximized in size. However, I'd ideally also want these windows to be minimized when they get created (mostly because it would make testing things a lot easier!) Is there any way to achieve this? I'm currently using Python 2.7 on Linux, with matplotlib version 1.3.1 using backend TkAgg.

If any other information is needed, just ask, and thanks in advance (even if it turns out it's not possible!).

Upvotes: 2

Views: 1128

Answers (2)

Mohammed Almalki
Mohammed Almalki

Reputation: 163

I think this code would help:

import matplotlib.pyplot as plt
import numpy as np

y = np.array([35, 25, 25, 15])
plt.pie(y)

manager = plt.get_current_fig_manager()

# this line will minimize the window after 0 ms of the window being displayed
manager.window.after(0, lambda: manager.window.iconify())

# this line will restored the window to normal after 0 ms of the window being displayed
# manager.window.after(0, lambda: manager.window.state('normal'))

# this line will maximize the window after 0 ms of the window being displayed
# manager.window.after(0, lambda: manager.window.state('zoomed'))

plt.show()

Upvotes: 0

Aguy
Aguy

Reputation: 8059

Try this after relevant plots:

mng = plt.get_current_fig_manager()
mng.window.showMaximized()
mng.window.showMinimized()

Upvotes: 1

Related Questions