I have two random vectors that are used to make a line plot. Using the same vectors, I would like to enlarge the line, but the animation is stable - it intrigues the original graph. Any suggestions on how to make such a line plot alive?
Import the NMP as import matlotlib import matlotlib from the import py # random line plot example x = np.random.rand (10) Y = np.random.rand (10) py.figure (3) py.plot (x, y, lw = 2) py.show () # animation line plot example fig = py.figure (4) ax = py axis (xlim = (0, 1 ), Ylim = (0, 1)), = ax.plot ([], [], lw = 2) def init (): line.set_data ([], []) Return line, Diff Amimet (I) : Line.sat_data (x, y) return line, animate = animation.funk animation (fig, ammate, init_funk = int, frames = 200, interval = 20, Lit = false) The last frame of the animation should look something like the plot below. Keep in mind that this is a random plot, so the actual number will change with each run.
OK, I think what you want to do is only i - for the animation frame i < / Em> The index of the frame In that case, you can use the frame number to limit the data displayed:
Import the NMP as the import matplotlib.pyplot as matplotlib import Animation py x = np.random.rand (10) y = np.random.rand (10) # animation line plot n Clue fig = py.figure (4) ax = py.axes (xlim = (0, 1), ylim = (0, 1)) line, = ax (I): line.set_data (x [: i], y [:] [], [A] I] return line, animatie = animation.function (fig, animate, init_funk = init, frames = lenan (x) +1, interval = 200, blit = folce) Notice changed the number of I frames to len (x) + 1
and the interval increased so that it is very slow to see.
Comments
Post a Comment