from matplotlib import pyplot as plt
# 創建實時繪製橫縱軸變量
x = []
y = []
# 創建繪製實時損失的動態窗口
plt.ion()
# 創建循環
for i in range(100):
x.append(i) # 添加i到x軸的數據中
y.append(i**2) # 添加i的平方到y軸的數據中
plt.clf() # 清除之前畫的圖
plt.plot(x, y * np.array([-1])) # 畫出當前x列表和y列表中的值的圖形
plt.pause(0.001) # 暫停一段時間,不然畫的太快會卡住顯示不出來
plt.ioff() # 關閉畫圖窗口
下面以繪製神經網絡損失值來展示效果: