Reputation: 58891
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?
Upvotes: 2
Views: 210
Reputation: 25380
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
Upvotes: 2