Combining PyGMT and Cartopy
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import pygmt
import numpy as np
import pandas as pd
region = [-125, -114, 32, 42]
df = pd.read_csv('data/earthquakes.csv')
df = df[(df['longitude'] >= region[0]) & (df['longitude'] <= region[1]) &
(df['latitude'] >= region[2]) & (df['latitude'] <= region[3])]
grid = pygmt.datasets.load_earth_relief(resolution="30s", region=region)
fig = plt.figure(figsize=(15, 10))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.set_extent(region)
img_extent = (grid.lon.min(), grid.lon.max(), grid.lat.min(), grid.lat.max())
ax.set_extent(region, crs=ccrs.PlateCarree())
ax.scatter(df['longitude'], df['latitude'],
s=df['magnitude']*10, alpha=0.5, c="red",
transform=ccrs.PlateCarree())
ax.imshow(grid.data, extent=img_extent, transform=ccrs.PlateCarree(),
cmap='terrain', origin='lower')
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.BORDERS)
ax.add_feature(cfeature.STATES)
ax.gridlines(draw_labels=True)
plt.colorbar(ax.images[0], label='Elevation (m)')
plt.title('California Topography (PyGMT + Cartopy)')
plt.show()