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 0x7f0fe2641f70>
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("irma.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: [789.0156292843434, 777.1209213051824, 763.9045791061146, 754.6531395667672, 742.7584315876063, 729.5420893885386, 718.9690156292844, 707.0743076501234, 689.8930627913354, 672.7118179325473, 654.2089388538525, 637.0276939950645, 617.2031806964629, 600.0219358376748, 578.8757883191664, 561.6945434603784, 549.7998354812174, 531.2969564025227, 524.6887853029888, 515.4373457636414, 508.8291746641075, 498.2561009048534, 494.291198245133, 485.03975870578563, 478.43158760625175, 470.50178228681114, 462.57197696737046, 454.6421716479298, 444.0690978886757, 436.139292569235, 426.88785302988754, 426.88785302988754, 417.6364134905402, 408.38497395119276, 399.1335344118454, 389.88209487249793, 389.88209487249793, 381.9522895530573, 372.70085001370995, 362.1277762544557, 352.8763367151084, 343.6248971757609, 340.9816287359473, 337.01672607622703, 334.37345763641343, 331.7301891965999, 329.08692075678647, 325.122018097066, 322.47874965725265, 319.83548121743905, 315.8705785577188, 313.2273101179052, 309.2624074581849, 306.6191390183713, 302.654236358651, 298.68933369893057, 294.7244310392103, 292.0811625993967, 289.4378941595833, 286.7946257197697, 277.54318618042225, 268.29174664107484, 259.04030710172736, 249.78886756238012, 240.53742802303267, 232.60762270359191, 220.71291472443107, 214.10474362489722, 202.21003564573618, 194.28023032629562, 185.02879078694818, 178.42061968741433, 169.16918014806686, 162.561009048533, 155.95283794899913, 148.0230326295586, 137.44995887030444, 134.80669043049085, 133.48505621058396, 132.16342199067728, 129.52015355086368, 128.198519330957, 126.8768851110501, 125.55525089114342, 122.91198245132982, 121.59034823142314, 121.59034823142314, 120.26871401151624, 118.94707979160954, 118.94707979160954, 117.62544557170285, 116.30381135179596, 114.98217713188927, 114.98217713188927, 113.66054291198238, 112.33890869207568, 113.66054291198238, 112.33890869207568, 112.33890869207568, 112.33890869207568, 112.33890869207568, 112.33890869207568, 112.33890869207568, 112.33890869207568, 111.01727447216899, 109.6956402522621, 108.37400603235541, 108.37400603235541, 109.6956402522621, 109.6956402522621, 108.37400603235541, 109.6956402522621, 109.6956402522621, 109.6956402522621, 108.37400603235541, 107.05237181244851, 107.05237181244851, 107.05237181244851, 104.40910337263513, 103.08746915272823, 97.80093227310127, 93.83602961338079, 91.1927611735674, 84.58459007403353, 79.29805319440636, 74.01151631477919, 67.40334521524532, 63.43844255552505, 39.64902659720318, 23.78941595832187] y-coords: [381.33333333333337, 381.33333333333337, 381.33333333333337, 380.0, 374.6666666666667, 369.3333333333333, 362.6666666666667, 357.33333333333337, 353.33333333333337, 349.3333333333333, 345.33333333333337, 346.66666666666663, 349.3333333333333, 353.33333333333337, 355.99999999999994, 360.0, 364.0, 365.3333333333333, 368.0, 370.66666666666663, 373.3333333333333, 374.6666666666667, 376.0, 376.0, 377.3333333333333, 377.3333333333333, 377.3333333333333, 377.3333333333333, 378.66666666666663, 378.66666666666663, 377.3333333333333, 377.3333333333333, 376.0, 374.6666666666667, 372.0, 370.66666666666663, 370.66666666666663, 368.0, 364.0, 361.3333333333333, 358.66666666666663, 357.33333333333337, 355.99999999999994, 354.6666666666667, 353.33333333333337, 352.0, 350.6666666666667, 349.3333333333333, 348.00000000000006, 346.66666666666663, 345.33333333333337, 344.0, 342.6666666666667, 341.33333333333337, 340.0, 338.66666666666663, 337.3333333333333, 337.3333333333333, 336.00000000000006, 333.33333333333337, 331.99999999999994, 328.0, 324.0, 321.3333333333333, 318.66666666666663, 315.99999999999994, 313.33333333333326, 310.6666666666667, 309.3333333333333, 306.66666666666663, 306.66666666666663, 305.3333333333333, 304.0, 305.3333333333333, 302.6666666666667, 300.0, 298.6666666666667, 296.0, 294.6666666666667, 293.33333333333337, 291.99999999999994, 291.99999999999994, 289.3333333333333, 288.0, 288.0, 288.0, 289.3333333333333, 288.0, 286.66666666666663, 286.66666666666663, 285.3333333333333, 284.00000000000006, 284.00000000000006, 281.33333333333337, 281.33333333333337, 278.6666666666667, 277.3333333333333, 274.6666666666667, 273.33333333333337, 271.99999999999994, 270.6666666666667, 269.3333333333333, 266.66666666666663, 266.66666666666663, 264.00000000000006, 261.33333333333337, 258.6666666666667, 257.3333333333333, 254.6666666666667, 253.33333333333337, 250.66666666666669, 249.33333333333334, 245.33333333333331, 244.00000000000003, 238.66666666666669, 236.0, 233.33333333333331, 230.66666666666669, 228.0, 223.99999999999997, 214.6666666666667, 206.66666666666666, 196.0, 189.33333333333334, 180.00000000000003, 174.66666666666666, 168.00000000000003, 160.00000000000003, 144.0, 131.99999999999997]
plt.imshow(img) plt.scatter(x, y, color='purple')
<matplotlib.collections.PathCollection at 0x7f0fe2578610>
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