您必須使用nan數組來繪製空值,然後更新您的數組隨着時間的推移。這裏是一個工作示例:
import numpy as np
import matplotlib.pyplot as plt
import time
nbPoints = 100
nanArray = np.array(np.ones(nbPoints))
nanArray[:] = np.nan
index = range(nbPoints)
minimum = np.random.randint(5, size=nbPoints)
minimumPlotData = nanArray
fig = plt.figure()
ax = plt.subplot(111)
ax.set_xlim(0, nbPoints)
ax.set_ylim(min(minimum), max(minimum))
li, = ax.plot(index,minimumPlotData, marker = 'o', linestyle="")
fig.canvas.draw()
plt.show(block=False)
for i in range(nbPoints):
minimumPlotData[i]=minimum[i]
li.set_ydata(minimumPlotData)
fig.canvas.draw()
time.sleep(1)
'它沒有工作'的意思?你能發佈完整的錯誤嗎? – Gianluca
沒有錯誤。它沒有工作意味着,繪圖過程不會逐步顯示。我只看到最後的情節。 – MaximeMusterFrau