简体   繁体   中英

There is no error message… but the plot is not being plotted

so I am following a tutorial of plotting values that change in the regular intervals(live data)... I am using matplotlib and using FuncAnimation... I have imported all the necessary modules but no answer... here is what i have done and the output

x = []
y = []
c = count()
def anim(i):
  x.append(next(c))
  y.append(random.randint(0,10))
  plt.cla()
  plt.plot(x,y,'or',markersize=10)
  

ani = FuncAnimation(plt.gcf(),anim,interval=5000)

the output:

<Figure size 432x288 with 0 Axes>

This section explains the basic structure of the animation.

  1. Configure the objects that will draw the graph. (Line 5)
  2. Set the Y value you want to animate with the animation function (def anim()).
  3. Then update the value of the graph object set in #1
  4. Set the number of times to draw, the interval between draws, the inability to repeat, etc. with Funcanimation() .
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import numpy as np

fig, ax = plt.subplots()

im, = ax.plot([], [], 'or', markersize=10)
x = np.arange(10)

ax.set_xlim(0, 9)
ax.set_ylim(0, 1)

def anim(i):
    y = np.random.rand(10)
    im.set_data(x, y)

anim = FuncAnimation(fig, anim, frames=50, interval=200, repeat=False, blit=False)

fig.show()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM