Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
614 views
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)
<matplotlib.image.AxesImage at 0x7fec900a60a0>
Image in a Jupyter notebook
# 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 # Convert from lat/long to pixel coordinates x_NY = (long_NY - left)*width/(right-left) y_NY = (height*(1 - (lat_NY - bottom)/(top-bottom))) # Print the pixel co-ordinates of New York print("NY x pos:", x_NY) print("NY y pos:", y_NY)
NY x pos: 211.46147518508363 NY y pos: 57.3333333333333
plt.imshow(img) plt.scatter(x_NY, y_NY) plt.text(x_NY, y_NY, "New York", color="white")
Text(211.46147518508363, 57.3333333333333, 'New York')
Image in a Jupyter notebook
import csv # load the code library for reading CSV files x = [] y = [] # Open the data file with open("bermuda.csv") as f: reader = csv.reader(f) # skip the first line of the file next(reader) for row in reader: latitude = float(row[2]) longitude = float(row[3]) # translate to pixel coordinates x.append((longitude - left)*width/(right-left)) y.append(height*(1 - (latitude - bottom)/(top-bottom))) print("x-coords:", x) print("y-coords:", y)
x-coords: [1616.4617384151359, 1529.9462407458186, 1433.5171647929806] y-coords: [-263.34000000000003, -469.22400000000005, -281.40933333333334]
plt.imshow(img) plt.scatter(x, y, color='orange')
<matplotlib.collections.PathCollection at 0x7fec901066d0>
Image in a Jupyter notebook
import matplotlib.animation as animation 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)
Image in a Jupyter notebook