我使用 while true 回圈在 python 中創建了一個 UI 選單:
import matplotlib.pyplot as plt
choice=input('enter a number')
while True:
if choice == '1':
pass
elif choice == '2':
pass
elif choice == '3':
plt.plot(range(100),range(100))
plt.show()
在 while 回圈之外運行它可以很好地繪制圖形,但在回圈內部,會顯示空數字,然后 python 崩潰。
為什么我不能在while回圈中繪制它。
編輯: 我已經能夠將問題簡化為:
import matplotlib.pyplot as plt
x,y=100
while True:
plt.plot(x,y)
似乎 while True 會導致問題。有任何想法嗎?
uj5u.com熱心網友回復:
嘗試plt.show()在回圈中使用
uj5u.com熱心網友回復:
import matplotlib.pyplot as plt
choice=input('enter a number')
while True:
if choice == '1':
pass
elif choice == '2':
pass
elif choice == '3':
plt.plot(range(100),range(100))
plt.show()
choice=input('enter a number')
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/457243.html
標籤:Python matplotlib
