-
Notifications
You must be signed in to change notification settings - Fork 2
Figure 4: pandas / tabular data - scatter plot - seismicity around Indonesia #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 70 commits
50d5364
465470e
4629685
994ee17
d0b965a
4a7d267
522f97d
47ba3ed
8cb30e8
c1fa0bd
718043d
d8238d7
6c1bfad
9691062
1fffdd2
e5e533f
312a93d
d629171
2114217
163ba84
6386a9d
00caf3e
3d59b2f
a312faf
62086f1
f7c7b14
0c7e1dd
391080e
f3140b3
a2e325f
bcc2e13
a346b03
b3f76ac
7534574
37c09db
6bdc2f7
0c8e75b
a913291
761d76e
a326d2e
1a02fa6
a312aea
9bdbbd3
143b3bb
1607022
7d3e43f
2924e23
92bf26e
41cab14
c1d1cac
11b43ad
fdb496f
e537f2b
206f8cd
decccde
d398690
cc64ea8
83f652f
a82687d
e639681
8ea9fa8
cfd9af5
ed591dc
b9fda48
97a8c7c
ccba97d
bdbbaaf
3e48031
12e6237
dd91f37
bed7149
12e8fb3
ab74ba2
c1df2e3
dbfeb4c
00e7e12
7eab108
3b2d9f5
6fe7ee5
aa06195
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 1, | ||
| "id": "533bc728-db2c-4f3a-ab3f-1f4f2c9ecd69", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Copy finale version of script from normal Python file" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3 (ipykernel)", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.12.3" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||
| import io | ||||||
|
|
||||||
| import pandas as pd | ||||||
| import pygmt | ||||||
| import requests | ||||||
| from pygmt.params import Box | ||||||
|
|
||||||
| params = { | ||||||
| "format": "csv", | ||||||
| "starttime": "2000-01-01", | ||||||
| "endtime": "2025-10-30", | ||||||
| "mindepth": 70, | ||||||
| "minmagnitude": 5, | ||||||
| "orderby": "magnitude", | ||||||
|
yvonnefroehlich marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
| r = requests.get("https://earthquake.usgs.gov/fdsnws/event/1/query", params=params) | ||||||
| df_eqs = pd.read_csv(io.StringIO(r.text)) | ||||||
| df_eqs = df_eqs[ | ||||||
| (df_eqs["longitude"] >= 91) | ||||||
| & (df_eqs["longitude"] <= 134) | ||||||
| & (df_eqs["latitude"] >= -22) | ||||||
| & (df_eqs["latitude"] <= 19) | ||||||
| & (df_eqs["magType"] != "mb") | ||||||
|
seisman marked this conversation as resolved.
Outdated
|
||||||
| ] | ||||||
|
yvonnefroehlich marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| fig = pygmt.Figure() | ||||||
| fig.basemap(region=[91, 134, -22, 19], projection="M15c", frame=True) | ||||||
| fig.coast(land="gray95", shorelines="gray50") | ||||||
|
|
||||||
| # Plot epicenters with color (hypocentral depth) or size (moment magnitude) | ||||||
| pygmt.makecpt(cmap="SCM/navia", series=[0, 700], reverse=True, transparency=30) | ||||||
| fig.colorbar(frame=["xaf+lHypocentral depth", "y+lkm"]) | ||||||
|
seisman marked this conversation as resolved.
Outdated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just simplify it to:
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. I placed the unit as y label to avoid that we have to think about having units in brackets or using a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, we can keep it now. But I feel the frame parameter is still not Pythonic and we may need to implement the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, yes, the frame parameter is maybe the most complicated parameter in GMT / PyGMT and provides a huge amount of quite different functionalities 🙂.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, maybe we should have a look at the author guidelines of |
||||||
| fig.plot( | ||||||
| x=df_eqs.longitude, | ||||||
| y=df_eqs.latitude, | ||||||
| size=0.005 * 2**df_eqs.mag, | ||||||
| fill=df_eqs.depth, | ||||||
| cmap=True, | ||||||
| style="c", | ||||||
| pen="gray10", | ||||||
|
yvonnefroehlich marked this conversation as resolved.
Outdated
|
||||||
| ) | ||||||
| # Add legend for size-coding | ||||||
| legend = io.StringIO( | ||||||
| "\n".join(f"S 0.4 c {0.005 * 2**mag:.2f} - 1p 1 Mw {mag}" for mag in [5, 6, 7]) | ||||||
|
michaelgrund marked this conversation as resolved.
Outdated
seisman marked this conversation as resolved.
Outdated
|
||||||
| ) | ||||||
| fig.legend(spec=legend, position="jBR+o0.2c+l2", box=Box(fill="white", pen="black")) | ||||||
|
|
||||||
| # Add histogram for moment magnitude distribution | ||||||
| with fig.inset(position="jBL+w7c/4c+o0.2c", margin=(1.2, 0.2, 0.9, 0.2), box=True): | ||||||
| with pygmt.config(FONT="8p"): | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need to set the FONT here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove it; please see my comment #5 (comment). And in addition, there are different themes in GMT which also affect the defaults. I think having different font sizes look OK.
|
||||||
| fig.histogram( | ||||||
| region=[4.8, 10.2, 0, 0], | ||||||
|
yvonnefroehlich marked this conversation as resolved.
Outdated
|
||||||
| projection="X?/?", | ||||||
| frame=["WSrt", "xa1f0.2+lMw", "yaf+lCounts"], | ||||||
| data=df_eqs.mag, | ||||||
| series=0.2, | ||||||
| fill="darkgray", | ||||||
| pen="lightgray", | ||||||
| histtype=0, | ||||||
| ) | ||||||
|
|
||||||
| fig.show() | ||||||
| fig.savefig("Fig4_PyGMT_pandas.png") | ||||||


Uh oh!
There was an error while loading. Please reload this page.