2

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?

2
  • I cannot reproduce the same results. When I maximize the figure, your code yields different value for me. Commented Jun 4, 2020 at 13:38
  • @ywbaek Interesting! By maximizing, you mean commenting in the figManager lines, right? Any idea what the issue might be? Commented Jun 4, 2020 at 13:42

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.