get size of maximized matplotlib figure

Viewed 92

I'd like to open a matplotlib figure maximized and I'd like to get the size of the figure in inches. This yields the same value no matter if the figure is maximized or not:

import matplotlib.pyplot as plt

# figManager = plt.get_current_fig_manager()
# figManager.window.showMaximized()

fig = plt.gcf()
height = fig.get_size_inches()[1]
print(height)
4.8

Any hints?

1 Answers

I suspect this is due to the time is takes to maximise/draw the figure itself. You could be catching the size of the figure before it is resized.

Introducing any length of pause solves the problem:

import matplotlib.pyplot as plt

figManager = plt.get_current_fig_manager()
figManager.window.showMaximized()

plt.pause(0.0001)

fig = plt.gcf()
height = fig.get_size_inches()[1]
print(height)
# 9.56      Commenting out the pause gives me the result 4.8
Related