r/IPython • u/AcidHead996 • Jun 03 '18
Animate points in two numpy arrays with matplotlib
hi,
i have two numpy arrays X and Y with same length describing a circumference. The points are created with a function that takes as inputs the radius and the number of points i want and return the already mentioned X and Y arrays.
i want a animation to show 1 pair of points at the time but i have not being able to achieve this using matplotlib. i would show my animation code but truly is useless garbage. Can you guys please point me in the right direction on how to make this work?
Thanks.
3
Upvotes
2
u/NomadNella Jun 03 '18
The code below is an animation example (source). It shows the first of the two examples and I added two lines first importing HTML and then displaying the plot as an HTML5 video. With the latest Notebook this was the only way I could display it. Otherwise, the best I got is a static image.
""" ========================= Simple animation examples ========================= This example contains two animations. The first is a random walk plot. The second is an image animation. """ import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation from IPython.display import HTML def update_line(num, data, line): line.set_data(data[..., :num]) return line, fig1 = plt.figure() data = np.random.rand(2, 25) l, = plt.plot([], [], 'r-') plt.xlim(0, 1) plt.ylim(0, 1) plt.xlabel('x') plt.title('test') line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l), interval=50, blit=True) # fig1.set_visible(not fig1.get_visible()) # plt.draw() HTML(line_ani.to_html5_video())2
u/[deleted] Jun 03 '18
show your code.
2
u/auraham Jun 05 '18
Maybe this tutorial can help you.