Now we will use trinket.io to make our own earthquake maps with Python. Trinkets allow you to run snippets of Python code directly in your internet browser! Just click the button in the top bar to run the code.
Our first example is a simple sinusoid with frequency $f$ and amplitude $A$:
$$ y = A \sin (f x) $$
Try making changes to the code and rerunning it to see how the output changes.
(We will be returning to waves in Part 2!)
Trinkets can also include data files. Here we have added a file called
earthquakes.csv, which contains a comma-separated list of all earthquakes greater than magnitude 5.0 from 2015–2020. The columns of the data file are
mag and can be loaded into a Pandas dataframe using a single line:
import pandas as pd # Load earthquake data df = pd.read_csv("earthquakes.csv")
The trinket below loads the data and plots it on top of a PNG image of the Earth. We have the option to filter the data based on depth (
max_depth) and magnitude (
- Where do deep earthquakes most commonly occur? Why?
- Are there more large or small magnitude earthquakes?
- CHALLENGE: Try building your own filter that only shows earthquakes within a specified latitude and longitude range.
Hint: Try modifying these lines in the trinket code to filter
#--------- FILTER DATA ----------# index_depth = (df.depth >= min_depth) & (df.depth <= max_depth) index_mag = (df.mag >= min_mag) & (df.mag <= max_mag) df_filt = df[index_depth & index_mag]