Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 2031
Image: ubuntu2004
Kernel: Python 3 (system-wide)
import matplotlib.pyplot as plt x = [5, 6] y = [6, 7] plt.figure(figsize=(2,2)) plt.scatter(x,y) plt.xlim(0, 10) plt.ylim(0, 10)
(0.0, 10.0)
Image in a Jupyter notebook
import matplotlib.image as mpi img = mpi.imread('atlantic-basin.png') plt.imshow(img) # latitude/longitude co-ordinates of edges of map left = -90 right = -17.06 bottom = 0 top = 45 # dimensions of image in pixels width = 964 height = 600 #lat/long of New York lat_NY = 40.7 long_NY = -74.0 x_NY = (long_NY + 90)*964/(right-left) y_NY = (height*(1 - (lat_NY - bottom)/(top-bottom))) print("NY x pos:", x_NY) print("NY y pos:", y_NY) plt.scatter(x_NY, y_NY) plt.text(x_NY, y_NY, "New York", color="white")
NY x pos: 211.46147518508363 NY y pos: 57.3333333333333
Text(211.46147518508363, 57.3333333333333, 'New York')
Image in a Jupyter notebook
import csv x = [] y = [] # Open the data file with open("irma.csv") as f: reader = csv.reader(f) next(reader) for row in reader: latitude = float(row[2]) longitude = float(row[3]) x.append((longitude + 90)*964/(right-left)) y.append((height*(1 - (latitude - bottom)/(top-bottom))) print("x-coords:", x) print("y-coords:", y)
File "<ipython-input-13-8151834dc555>", line 15 y.append((height*(1 - (latitude - bottom)/(top-bottom))) ^ SyntaxError: unexpected EOF while parsing
plt.imshow(img) plt.scatter(x, y, color='purple')
<matplotlib.collections.PathCollection at 0x7f93f6762b20>
Image in a Jupyter notebook
from matplotlib import animation ims = [] for i in range(10): im = plt.imshow(img, animated=True) plt.scatter(i*90, 300) ims.append([im]) fig = plt.figure() ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True, repeat_delay=1000)
Image in a Jupyter notebook
<Figure size 864x504 with 0 Axes>
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation import matplotlib.image as mpi img = mpi.imread('atlantic-basin.png') fig = plt.figure() ax = plt.axes() patch = plt.Circle((0, 0), 20, fc='y') def init(): patch.center = (20, 20) ax.add_patch(patch) return patch, def animate(i): patch.center = (x[i], y[i]) return patch, anim = animation.FuncAnimation(fig, animate, init_func=init, frames=len(x), interval=20, blit=True) plt.imshow(img,zorder=0) anim.save('hurricane_irma.mp4', writer = 'ffmpeg', fps=30) plt.show()
Image in a Jupyter notebook
latitude-bottom
35.1