From 2f42bc189fde2b092870ded35486ef34d45cc4c7 Mon Sep 17 00:00:00 2001 From: Moez <65367982+moezmustafa@users.noreply.github.com> Date: Sat, 28 Oct 2023 18:55:29 +0500 Subject: [PATCH] Create animation.py --- animation.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 animation.py diff --git a/animation.py b/animation.py new file mode 100644 index 00000000..2d90772f --- /dev/null +++ b/animation.py @@ -0,0 +1,30 @@ +import matplotlib.pyplot as plt +from matplotlib.animation import FuncAnimation + +# Create a figure and axis +fig, ax = plt.subplots() + +# Initialize an empty plot +line, = ax.plot([], [], lw=2) + +# Set the axis limits +ax.set_xlim(0, 2 * 3.14) +ax.set_ylim(-1, 1) + +# Function to initialize the plot +def init(): + line.set_data([], []) + return line, + +# Function to update the plot in each frame +def update(frame): + x = 2 * 3.14 * frame / 100 + y = 0.5 * (1 + frame / 100) + line.set_data(x, y) + return line, + +# Create an animation +ani = FuncAnimation(fig, update, frames=100, init_func=init, blit=True) + +# Display the animation (this may vary depending on your Python environment) +plt.show()