Skip to content Skip to sidebar Skip to footer

Simple Animation Of 2d Coordinates Using Matplotlib And Pyplot

I am new to matplotlib. I have a list of x-y coordinates that I update in python and want to animate using matplotlib's pyplot. I want to specify the x-range and y-range in advance

Solution 1:

This is adapted from the animation demo:

import matplotlib.pyplot as plt 
import numpy as np

fig, ax = plt.subplots()

x = [1, 2, 3, 4]
y = [5, 6, 7, 8]

for t inrange(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 this is simple the docstring say that it is slow.

Post a Comment for "Simple Animation Of 2d Coordinates Using Matplotlib And Pyplot"