[問題] matplotlib.pyplot關不起來
from PIL import Image
import matplotlib.pyplot as plt
im = Image.open("./1.jpg")
plt.figure("1")
plt.imshow(im) #繪製圖片
plt.show() #顯示圖片
plt.close() #關閉圖片
程式碼如上
路徑沒有問題 圖片可以正常顯示 但沒辦法關閉圖片
只能自己手動關閉 才會繼續跑下一行
環境是用anaconda安裝的 使用vscode執行
有看過plt.close可以執行的參數 都試過了
想請教問題出在哪裡
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.32.56.155
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1553145749.A.CA9.html
plt.show() is a blocking function, so in the example code you used above,
plt.close() isn't being executed until the window is closed, which makes it
redundant.
You can use plt.ion() at the beginning of your code to make it non-blocking,
although this has other implications.
有查到預設是blocking function 所以並不會繼續執行直到被手動關閉
若是加入指令plt.ion變成交互模式 反而不會顯示圖片
所以目前就會呈現一個狀態
可以自動關閉圖片 但不會顯示圖片
或是得手動關閉圖片 自動顯示下一張 但是圖片出的來
※ 編輯: alen84204 (114.32.56.155), 03/21/2019 13:38:22
推
03/21 15:43,
6年前
, 1F
03/21 15:43, 1F
→
03/21 15:43,
6年前
, 2F
03/21 15:43, 2F
→
03/21 15:43,
6年前
, 3F
03/21 15:43, 3F
→
03/21 15:44,
6年前
, 4F
03/21 15:44, 4F

有試過關閉非交互模式
問題是只要在交互模式下 plt.show(block=False) 就會呈現沒有回應的狀態
問題依舊無法解決 感謝您的回覆
※ 編輯: alen84204 (114.32.56.155), 03/22/2019 10:10:55
推
03/23 08:42,
6年前
, 5F
03/23 08:42, 5F
→
03/23 11:06,
6年前
, 6F
03/23 11:06, 6F
→
03/23 11:07,
6年前
, 7F
03/23 11:07, 7F
→
03/23 11:07,
6年前
, 8F
03/23 11:07, 8F
→
03/23 14:33,
6年前
, 9F
03/23 14:33, 9F
→
04/04 13:18,
6年前
, 10F
04/04 13:18, 10F
Python 近期熱門文章
PTT數位生活區 即時熱門文章