Skip to content

Commit 8b1a27d

Browse files
yvonnefroehlichseismanmichaelgrund
authored
Figure 4: pandas / tabular data - scatter plot - seismicity around Indonesia (#5)
Co-authored-by: Dongdong Tian <seisman.info@gmail.com> Co-authored-by: Michael Grund <23025878+michaelgrund@users.noreply.github.com>
1 parent 4440791 commit 8b1a27d

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

Fig4_PyGMT_pandas.ipynb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "533bc728-db2c-4f3a-ab3f-1f4f2c9ecd69",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import io\n",
11+
"\n",
12+
"import pandas as pd\n",
13+
"import pygmt\n",
14+
"import requests\n",
15+
"from pygmt.params import Box\n",
16+
"\n",
17+
"params = {\n",
18+
" \"format\": \"csv\",\n",
19+
" \"starttime\": \"2000-01-01\",\n",
20+
" \"endtime\": \"2025-10-30\",\n",
21+
" \"mindepth\": 70,\n",
22+
" \"minmagnitude\": 5,\n",
23+
"}\n",
24+
"r = requests.get(\"https://earthquake.usgs.gov/fdsnws/event/1/query\", params=params)\n",
25+
"df_eqs = pd.read_csv(io.StringIO(r.text))\n",
26+
"df_eqs = df_eqs[\n",
27+
" (df_eqs[\"longitude\"] >= 91)\n",
28+
" & (df_eqs[\"longitude\"] <= 134)\n",
29+
" & (df_eqs[\"latitude\"] >= -22)\n",
30+
" & (df_eqs[\"latitude\"] <= 18)\n",
31+
"].sort_values(by=\"mag\", ascending=False)\n",
32+
"\n",
33+
"fig = pygmt.Figure()\n",
34+
"fig.basemap(region=[91, 134, -22, 18], projection=\"M15c\", frame=True)\n",
35+
"fig.coast(land=\"gray95\", shorelines=\"gray50\")\n",
36+
"\n",
37+
"# Plot epicenters with color (hypocentral depth) or size (magnitude)\n",
38+
"pygmt.makecpt(cmap=\"SCM/navia\", series=[0, 700], reverse=True, transparency=30)\n",
39+
"fig.plot(\n",
40+
" x=df_eqs.longitude,\n",
41+
" y=df_eqs.latitude,\n",
42+
" style=\"c\",\n",
43+
" size=0.005 * 2**df_eqs.mag,\n",
44+
" fill=df_eqs.depth,\n",
45+
" cmap=True,\n",
46+
" pen=\"gray10\",\n",
47+
")\n",
48+
"fig.colorbar(frame=[\"xaf+lHypocentral depth\", \"y+lkm\"])\n",
49+
"# Add legend for size-coding\n",
50+
"legend = io.StringIO(\n",
51+
" \"\\n\".join(f\"S 0.4 c {0.005 * 2**mag:.2f} - 1p 1 M {mag}\" for mag in [5, 6, 7])\n",
52+
")\n",
53+
"fig.legend(spec=legend, position=\"jBR+o0.2c+l2\", box=Box(fill=\"white\", pen=\"black\"))\n",
54+
"\n",
55+
"# Add histogram for magnitude distribution\n",
56+
"with fig.inset(position=\"jBL+w7c/4c+o0.2c\", margin=(1.3, 0.2, 1.1, 0.2), box=True):\n",
57+
" fig.histogram(\n",
58+
" region=[4.8, 9.2, 0, 0],\n",
59+
" projection=\"X?/?\",\n",
60+
" frame=[\"WSrt\", \"xa1f0.2+lMagnitude\", \"yaf+lCounts\"],\n",
61+
" data=df_eqs.mag,\n",
62+
" series=0.2,\n",
63+
" fill=\"darkgray\",\n",
64+
" pen=\"lightgray\",\n",
65+
" histtype=0,\n",
66+
" )\n",
67+
"\n",
68+
"fig.show()\n",
69+
"# fig.savefig(\"Fig4_PyGMT_pandas.png\")"
70+
]
71+
}
72+
],
73+
"metadata": {
74+
"kernelspec": {
75+
"display_name": "Python 3 (ipykernel)",
76+
"language": "python",
77+
"name": "python3"
78+
},
79+
"language_info": {
80+
"codemirror_mode": {
81+
"name": "ipython",
82+
"version": 3
83+
},
84+
"file_extension": ".py",
85+
"mimetype": "text/x-python",
86+
"name": "python",
87+
"nbconvert_exporter": "python",
88+
"pygments_lexer": "ipython3",
89+
"version": "3.12.3"
90+
}
91+
},
92+
"nbformat": 4,
93+
"nbformat_minor": 5
94+
}

0 commit comments

Comments
 (0)