How to plot the earthquakes data on a topographic map

Read the earthquake data from a csv file and overlay on a topographic map using PyGMT.

In this post, we will first read a CSV file with earthquake locations (latitudes, and longitudes), magnitudes, and depths, and then overlay it on a topographic map. The topographic data are downloaded automatically using PyGMT API.

Read the csv file for events data

I have a csv file containing the earthquake events data. The data is obtained from the PyGMT example dataset. It can be obtained and saved locally:

data = pygmt.datasets.load_japan_quakes()
data.to_csv('my_events_data.csv', index=False)

The data is tabular, so we can read it using the pandas’ read_csv method.

import pandas as pd

# this file is retrieved from the pygmt dataset
data = pd.read_csv('my_events_data.csv')

Earthquake data
Earthquake data

Plot the data on a topographic map

First, we define the region based on the data.

# Set the region
region = [
    data.longitude.min() - 1,
    data.longitude.max() + 1,
    data.latitude.min() - 1,
    data.latitude.max() + 1,
]

Then we initialize the pygmt “Figure” object:

fig = pygmt.Figure()

Next, we obtain the high-resolution topographic data and plot it using the normalized etopo1 colormap. We set the minimum elevation of -8000 m and a maximum of 5000 m. If there are any topographic regions outside this range then it will be plotted with white. We select the “Mercator” projection with a width of 4 inches for plotting.

# make color pallets
pygmt.makecpt(
    cmap='etopo1',
    series='-8000/5000/1000', #min elevation of -8000m and max of 5000m
    continuous=True
)

# define etopo data file
topo_data = "@earth_relief_30s"
# plot high res topography
fig.grdimage(
    grid=topo_data,
    region=region,
    projection='M4i',
    shading=True,
    frame=True
)

We next plot the coastlines with shorelines, and also added a frame to the map.

fig.coast(shorelines=True, frame=True)

Finally, we plot the data:

# colorbar colormap
pygmt.makecpt(cmap="jet", series=[
              data.depth_km.min(), data.depth_km.max()])
fig.plot(
    x=data.longitude,
    y=data.latitude,
    sizes=0.1*data.magnitude,
    color=data.depth_km,
    cmap=True,
    style="cc",
    pen="black",
)
fig.colorbar(frame='af+l"Depth (km)"')
fig.savefig('my_earthquakes.png')

We plot the data with color representing the depths of the earthquakes and the size of the circles representing the magnitudes of the earthquakes. We added the horizontal color bar at the bottom.

import pygmt
import pandas as pd

# Load the data
data = pd.read_csv('my_events_data.csv')

# Set the region
region = [
    data.longitude.min() - 1,
    data.longitude.max() + 1,
    data.latitude.min() - 1,
    data.latitude.max() + 1,
]

fig = pygmt.Figure()

# Create color palette for topography
pygmt.makecpt(
    cmap='etopo1',
    series='-8000/5000/1000',
    continuous=True
)

# Define etopo data file
topo_data = "@earth_relief_30s"

# Plot high-resolution topography
fig.grdimage(
    grid=topo_data,
    region=region,
    projection='M4i',
    shading=True,
    frame=True
)
fig.coast(shorelines=True, frame=True)

# Create color palette for earthquake depths
pygmt.makecpt(cmap="jet", series=[
              data.depth_km.min(), data.depth_km.max()])

# Plot earthquake data
fig.plot(
    x=data.longitude,
    y=data.latitude,
    size=0.1 * data.magnitude,
    fill=data.depth_km,
    cmap=True,
    style="cc",
    pen="black",
)

# Add a colorbar
fig.colorbar(frame='af+l"Depth (km)"')

# Save the figure
fig.savefig('my_earthquakes.png')

Utpal Kumar
Utpal Kumar

Geophysicist | Geodesist | Seismologist | Open-source Developer
I am a geophysicist with a background in computational geophysics, currently working as a postdoctoral researcher at UC Berkeley. My research focuses on seismic data analysis, structural health monitoring, and understanding deep Earth structures. I have had the opportunity to work on diverse projects, from investigating building characteristics using smartphone data to developing 3D models of the Earth's mantle beneath the Yellowstone hotspot.

In addition to my research, I have experience in cloud computing, high-performance computing, and single-board computers, which I have applied in various projects. This includes working with platforms like AWS, Docker, and Kubernetes, as well as supercomputing environments such as STAMPEDE2, ANVIL, Savio and PERLMUTTER (and CORI). My work involves developing innovative solutions for structural health monitoring and advancing real-time seismic response analysis. I am committed to applying these skills to further research in computational seismology and structural health monitoring.

Articles: 29

Leave a Reply

Your email address will not be published. Required fields are marked *