动画 matplotlib 图形上的线条未显示



我不确定为什么我的小部件上没有显示图形线。

x 轴随时间移动,当我打印应绘制的 y 值 (Temp( 时,新值按预期出现。但是,绘图上没有显示线/点。

我过去在绘图中遇到过类似的问题,通过更改绘制的点的样式(即使用"r*"使点可见红色星星(来解决。我不确定如何在此代码中实现相同类型的东西。

import matplotlib.pyplot as plt
import numpy
import datetime
import matplotlib.animation as animation
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
def animate(i):
Time = []
Temp = []
x = datetime.datetime.now()
y = numpy.random.randint(48,52)
Time.append(x)
Temp.append(int(y))    
ax1.plot(Time,Temp)
print(Temp)
ani = animation.FuncAnimation(fig,animate, interval=1000)
plt.show()

只是将时间和温度从函数动画中移除

Time = []
Temp = []
def animate(i):
x = datetime.datetime.now()
y = numpy.random.randint(48,52)
Time.append(x)
Temp.append(int(y))    
ax1.plot(Time,Temp)
print(Temp)

您可以添加marker,它会显示点:

ax1.plot(Time,Temp, marker="s")

最新更新