python - Simple animation of 2D coordinates using matplotlib and pyplot -
i new matplotlib. have list of x-y coordinates update in python , want animate using matplotlib's pyplot. want specify x-range , y-range in advance. below current code:
import matplotlib.pyplot plt x=[1,2,3,4] y=[5,6,7,8] t in range(100): #lists x , y updated here #... plt.plot(x, y, marker='o', linestyle='none') plt.show() as can see, use plt.plot() , plt.show() at end of iteration loop plot final coordinates. want put step inside loop , plot @ every iteration specified pause time have animation loop runs.
just moving statement inside loop or tweaks thereabout aren't working. want keep simple though, , don't want use matplotlib.animation. there simple method without using many more modules , libraries (only stuff plt.pause() , perhaps bit more) let me want?
i looked @ many places online, , problem face methods there using python(x,y) (that's python version 2.7) on windows this, , animations using complicated modules , libraries crashing here.
however, able run simple stuff this example on matplotlib site, close want, not quite. perhaps best thing modification of example works case of 2d data (that example 1d row). other suggestion welcome.
this adapted animation demo:
import matplotlib.pyplot plt import numpy np fig, ax = plt.subplots() x = [1, 2, 3, 4] y = [5, 6, 7, 8] t in range(10): if t == 0: points, = ax.plot(x, y, marker='o', linestyle='none') ax.set_xlim(0, 10) ax.set_ylim(0, 10) else: new_x = np.random.randint(10, size=5) new_y = np.random.randint(10, size=5) points.set_data(new_x, new_y) plt.pause(0.5) while simple docstring slow.
Comments
Post a Comment