Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- from matplotlib.animation import FuncAnimation
- import numpy as np
- plt.style.use('dark_background')
- n_points = 1000
- A, B = 5.5, 6
- SIZE = 20
- theta = np.linspace(0, 2 * np.pi, n_points)
- frame = plt.gca()
- fig, axs = plt.subplots(1, 2)
- fig.suptitle('Same orbit, different reference frames')
- for ax in axs:
- ax.set_xlim(-7, 7)
- ax.set_ylim(-7, 7)
- ax.get_xaxis().set_visible(False)
- ax.get_yaxis().set_visible(False)
- x = A * np.sin(theta)
- y = B * np.cos(theta)
- xx = -A * np.sin(theta)
- yy = -B * np.cos(theta)
- orbit1 = axs[0].plot([], [], 'b.', markersize=SIZE)[0]
- orbit2 = axs[1].plot([], [], 'r.', markersize=SIZE)[0]
- axs[0].plot(0, 0, '.', markersize=SIZE, color="red")
- axs[1].plot(0, 0, '.', markersize=SIZE, color="blue")
- #plt.grid(True, lw=0.3)
- axs[0].plot(x, y, 'b-')
- axs[1].plot(xx, yy, 'r-')
- def animate(i):
- orbit1.set_data(x[i], y[i])
- orbit2.set_data(xx[i], yy[i])
- return orbit1, orbit2
- anim = FuncAnimation(fig, animate, frames=n_points, interval=10, repeat=False, blit=True)
- frame.axes.get_xaxis().set_visible(False)
- frame.axes.get_yaxis().set_visible(False)
- anim.save('planets.gif', writer='pillow')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment