最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Matplotlib show function is showing the plot window minmized after python input command - Stack Overflow

programmeradmin4浏览0评论

Im seeing strange behavior to the matplotlib plot.show() function as result of the python input command as in the below code. If I take the input command the plot window will show up and centered to the sceen, however if I add it back the plot window will be minimized. Im sure this is related to focus but not sure how to fix it.

import matplotlib.pyplot as plt
import numpy as np
import tkinter

#Remove the input line to see the difference 
input("presse any key  to continue...")
y = np.array([35, 25, 25, 15])
plt.pie(y)
plt.show() 

I tried the below suggestions but none worked or even compiled correctly specially around using the windowmanager.

Matplotlib; open plots minimized? How to maximize a plt.show() window

Im using python 3.11 and running my code with Visual Code on windows 11 machine.

I'm just looking to display it with normal behavior not minimized nor maximized.

Thanks

Im seeing strange behavior to the matplotlib plot.show() function as result of the python input command as in the below code. If I take the input command the plot window will show up and centered to the sceen, however if I add it back the plot window will be minimized. Im sure this is related to focus but not sure how to fix it.

import matplotlib.pyplot as plt
import numpy as np
import tkinter

#Remove the input line to see the difference 
input("presse any key  to continue...")
y = np.array([35, 25, 25, 15])
plt.pie(y)
plt.show() 

I tried the below suggestions but none worked or even compiled correctly specially around using the windowmanager.

Matplotlib; open plots minimized? How to maximize a plt.show() window

Im using python 3.11 and running my code with Visual Code on windows 11 machine.

I'm just looking to display it with normal behavior not minimized nor maximized.

Thanks

Share Improve this question edited 11 hours ago pippo1980 3,0963 gold badges17 silver badges39 bronze badges asked 2 days ago samsal77samsal77 7391 gold badge5 silver badges7 bronze badges 1
  • 2 I'm running Python in a similar environment and was not able to reproduce that behavior. In both cases, the plot shows normally – Ben Grossmann Commented 2 days ago
Add a comment  | 

2 Answers 2

Reset to default 0

this behavior is not happening to me,

but I have tried some things I hope they help,

try this solution:

import matplotlib.pyplot as plt
import numpy as np
import tkinter

#Remove the input line to see the difference 
input("press any key  to continue...")
y = np.array([35, 25, 25, 15])
plt.pie(y)

manager = plt.get_current_fig_manager()

# manager.window.state('normal')

# manager.window.state('withdrawn')

# manager.window.minsize(800, 500)

# manager.window.state('zoomed')

# manager.window.state('iconic')


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

# Schedule the window to be restored to normal.
manager.window.after(0, lambda: manager.window.state('normal'))

# Schedule the maximize action once the mainloop starts.
# 'zoomed' works on Windows; it may vary on other systems.
# manager.window.after(0, lambda: manager.window.state('zoomed'))

plt.show()

I guess the plot window is minimized because of how window focus is handled once the input command completed. Instead of using input() for a pause, you may use time.sleep() to introduce a short delay

import matplotlib.pyplot as plt
import numpy as np
import time

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

# Add a small delay instead of input
time.sleep(2)

you can try other options, such as

plt.ioff() to use Matplotlib's interactive mode, which may help avoid the window minimization issue

plt.pause(2) to pause for 2 seconds instead of input()

发布评论

评论列表(0)

  1. 暂无评论