Plotting Recent Earthquake Locations

The U.S. Geological Survey (USGS) has raw data available online. More info at the USGS earthquakes page.

This notebook was started by Physics teacher and Quarknet member Peter Apps, York Middle/High School, Retsof, NY.


In [1]:
#importing what we'll need
import numpy as np
import pandas as pd
%matplotlib inline
import matplotlib.pyplot as plt

Choose your data

In the box below, uncomment one of the data sets by deleting the # at the beginning of the line. Here's the full listing of the different data sets you can grab.


In [2]:
# Just earthquakes from the past hour
#data = pd.read_csv("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.csv")

# All earthquake events in the last month
data = pd.read_csv("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv")

# Only large earthquakes (magnitude 4.5 or greater) in teh past month
#data = pd.read_csv("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_month.csv")

In [3]:
data.head(4)


Out[3]:
time latitude longitude depth mag magType nst gap dmin rms ... updated place type horizontalError depthError magError magNst status locationSource magSource
0 2017-03-29T12:56:54.242Z 64.887400 -149.593000 18.60 1.10 ml NaN NaN NaN 0.68 ... 2017-03-29T13:01:47.100Z 41km NNW of North Nenana, Alaska earthquake NaN 0.10 NaN NaN automatic ak ak
1 2017-03-29T12:36:32.275Z 63.474300 -151.565500 0.00 1.40 ml NaN NaN NaN 0.62 ... 2017-03-29T12:44:47.448Z 130km W of Cantwell, Alaska earthquake NaN 0.30 NaN NaN automatic ak ak
2 2017-03-29T12:35:40.820Z 37.610001 -118.856331 2.35 0.95 md 9.0 140.0 0.0104 0.01 ... 2017-03-29T12:41:02.897Z 11km ESE of Mammoth Lakes, California earthquake 0.51 0.97 0.210 9.0 automatic nc nc
3 2017-03-29T12:17:47.900Z 35.542333 -118.391667 -0.16 1.74 ml 20.0 107.0 0.1377 0.14 ... 2017-03-29T12:21:53.196Z 10km ESE of Bodfish, CA earthquake 0.26 31.61 0.263 26.0 automatic ci ci

4 rows × 22 columns


In [4]:
# Set variables for scatter plot
x = data.longitude
y = data.latitude

plt.scatter(x,y)
plt.title('Earthquakes around the world (last month)')
plt.xlabel('Longitude')
plt.ylabel('Latitude')

# This actually shows the plot
plt.show()


Do you notice a pattern in the plot?

Run a new analysis

You can edit the code, maybe grab a different data set, and run the program again by going to Kernel > Restart & Run All


In [ ]: