Skip to content

Instantly share code, notes, and snippets.

@lgrachov
Created August 18, 2024 23:10
Show Gist options
  • Save lgrachov/1d3d3963fd71148d48033a8edef932b9 to your computer and use it in GitHub Desktop.
Save lgrachov/1d3d3963fd71148d48033a8edef932b9 to your computer and use it in GitHub Desktop.
Sine wave in Python
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