Last active
July 28, 2016 13:51
-
-
Save folkengine/d3ef2a56050895c88f19 to your computer and use it in GitHub Desktop.
Plotting Earthquakes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
import csv | |
from urllib.request import urlopen | |
# Based on http://introtopython.org/visualization_earthquakes.html | |
lats, lons = [], [] | |
magnitudes = [] | |
html = urlopen("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_week.csv") | |
next(html) | |
for line in html: | |
#print(line) | |
lats.append(float(line[1])) | |
lons.append(float(line[2])) | |
magnitudes.append(float(line[4])) | |
print('lats', lats[0:5]) | |
print('lons', lons[0:5]) | |
# --- Build Map --- | |
from mpl_toolkits.basemap import Basemap | |
import matplotlib.pyplot as plt | |
import numpy as np | |
eq_map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0, | |
lat_0=0, lon_0=-130) | |
eq_map.drawcoastlines() | |
eq_map.drawcountries() | |
eq_map.fillcontinents(color = 'gray') | |
eq_map.drawmapboundary() | |
eq_map.drawmeridians(np.arange(0, 360, 30)) | |
eq_map.drawparallels(np.arange(-90, 90, 30)) | |
min_marker_size = 2.5 | |
for lon, lat, mag in zip(lons, lats, magnitudes): | |
x,y = eq_map(lon, lat) | |
msize = mag * min_marker_size / 4 | |
eq_map.plot(x, y, 'ro', markersize=msize) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment