Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
614 views
ubuntu2004
Kernel: Python 3 (system-wide)
import numpy as np # set values of constants v_0 = 5 # initial velocity y_0 = 200 # initial y position g = 9.81 # acceleration due to gravity # calculate y for integer values of t from 0 to 9 t = np.arange(0, 10) y = y_0 - 0.5 * g * t ** 2 x = v_0 * t print("t (seconds):", t) print("y (metres):", y) print("x (metres):", x) import matplotlib.pyplot as plt plt.figure(figsize=(5,5)) plt.plot(t, y) plt.figure(figsize=(5,5)) plt.plot(t, x) plt.figure(figsize=(5,5)) plt.plot(x, y)
t (seconds): [0 1 2 3 4 5 6 7 8 9] y (metres): [ 200. 195.095 180.38 155.855 121.52 77.375 23.42 -40.345 -113.92 -197.305] x (metres): [ 0 5 10 15 20 25 30 35 40 45]
[<matplotlib.lines.Line2D at 0x7f6081e1b820>]
Image in a Jupyter notebookImage in a Jupyter notebookImage in a Jupyter notebook
t = np.arange(0, 365) d = 149600000 p = 365 x = d * np.cos(2 * np.pi * t * (1 / p)) y = d * np.sin(2 * np.pi * t * (1 / p))
from matplotlib import animation from IPython.display import HTML, display import random filename = "animation.gif" # Number of animation frames equals the length of time array t frames = len(t) // interval = 100 def ganimate(frame): plt.cla() plt.scatter(x[frame], y[frame]) plt.scatter(0, 0) plt.xlim(-159600000, 159600000) plt.ylim(-159600000, 159600000)
fig = plt.figure(figsize=(5, 5)) anim = animation.FuncAnimation(fig, ganimate, frames=frames, interval=interval) anim.save(filename, writer='imagemagick') plt.close() __counter__ = str(random.randint(0,2e9)) display(HTML('<img src="' + filename + '?' + __counter__ + '">'))
/usr/local/lib/python3.8/dist-packages/matplotlib/animation.py:973: UserWarning: Animation was deleted without rendering anything. This is most likely unintended. To prevent deletion, assign the Animation to a variable that exists for as long as you need the Animation. warnings.warn(