Created
August 18, 2024 23:10
-
-
Save lgrachov/1d3d3963fd71148d48033a8edef932b9 to your computer and use it in GitHub Desktop.
Sine wave in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
# Set up the figure and axis | |
fig, ax = plt.subplots() | |
x = np.linspace(0, 2 * np.pi, 100) # X values from 0 to 2π | |
line, = ax.plot(x, np.sin(x)) # Initial sine wave | |
ax.set_ylim(-1.5, 1.5) # Set y-axis limits | |
ax.set_title('Sine wave animation') | |
ax.set_xlabel('X-axis') | |
ax.set_ylabel('Y-axis') | |
# Animation function | |
def animate(i): | |
line.set_ydata(np.sin(x + i / 10.0)) # Update the Y data | |
return line, | |
# Create the animation | |
ani = animation.FuncAnimation(fig, animate, frames=100, interval=50, blit=True) | |
# Show the animation | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment