Here, I am plotting one sine wave, so I used np.linspace() to create the x-axis data and created y by calling np.sin() on x. Note that you must include a comma after line,! The plot method returns a tuple, and you need to unpack it to create the variable line. You can also think of it as initializing an empty line object that you will soon fill with data. You need to do this because animate modifies this line, and it can only modify something that already exists. Then, I did something you have probably never done before: I drew a blank line. Note that I included padding of 0.1 on each axis limit so that you can see the whole line matplotlib draws. ![]() Set up the Figure and Axes objects using plt.subplots() and – using ax.set() – set the x- and y-axis limits to the same size as a normal sine curve – from 0 to 2π on the x-axis and from -1 to 1 on the y-axis. # Set up empty Figure, Axes and Line objects Import NumPy and matplotlib using their standard aliases and FuncAnimation from matplotlib.animation. # Standard importsįrom matplotlib.animation import FuncAnimation Creating animations with matplotlib is different from creating static plots. Note that this code may look strange to you when you first read it. Let’s create a sin wave that matplotlib ‘draws’ for us.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
June 2023
Categories |