Skip to content

Commit 203d079

Browse files
Figure 1: Comparison of GMT and PyGMT syntax (#4)
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
1 parent 97d4b47 commit 203d079

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

Fig1_PyGMT_GMT_comparison.ipynb

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "0dfaa938-057e-4201-a936-a17c7a1009a9",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"# The PyGMT version:\n",
11+
"import pygmt\n",
12+
"\n",
13+
"fig = pygmt.Figure()\n",
14+
"fig.basemap(projection=\"N15c\", region=[0, 360, -90, 90], frame=True)\n",
15+
"fig.coast(land=\"tan\", water=\"lightblue\")\n",
16+
"fig.text(position=\"MC\", text=\"GMT\", font=\"80p,Helvetica-Bold,red@75\")\n",
17+
"fig.show()\n",
18+
"fig.savefig(\"PyGMT_map.png\")"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"id": "7d56a075-5a02-4730-8c35-2aef38027739",
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"%%bash\n",
29+
"# The GMT CLI version:\n",
30+
"gmt begin GMT_map png\n",
31+
" gmt basemap -JN15c -R0/360/-90/90 -B\n",
32+
" gmt coast -Gtan -Slightblue\n",
33+
" echo GMT | gmt text -F+f80p,Helvetica-Bold,red@75+cMC\n",
34+
"gmt end show"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": null,
40+
"id": "b304fb4a-d258-470f-89a7-6b2da0ca9283",
41+
"metadata": {},
42+
"outputs": [],
43+
"source": [
44+
"# Sequence of strings for the PyGMT code.\n",
45+
"pygmt_str = \"\"\"\n",
46+
"import pygmt\n",
47+
"\n",
48+
"fig = pygmt.Figure()\n",
49+
"fig.basemap(projection=\"N15c\", region=[0, 360, -90, 90], frame=True)\n",
50+
"fig.coast(land=\"tan\", water=\"lightblue\")\n",
51+
"fig.text(position=\"MC\", text=\"GMT\", font=\"80p,Helvetica-Bold,red@@75\")\n",
52+
"fig.show()\n",
53+
"fig.savefig(\"PyGMT_map.png\")\n",
54+
"\"\"\".splitlines()"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"id": "1c229785-c7dc-49e7-960d-c528aee8995a",
61+
"metadata": {},
62+
"outputs": [],
63+
"source": [
64+
"# Sequence of strings for the GMT CLI code.\n",
65+
"# The leading tab characters are intentional to match the indentation.\n",
66+
"gmt_str = \"\"\"\n",
67+
"gmt begin GMT_map png\n",
68+
"\\tgmt basemap -JN15c -R0/360/-90/90 -B\n",
69+
"\\tgmt coast -Gtan -Slightblue\n",
70+
"\\techo GMT | gmt text -F+f80p,Helvetica-Bold,red@@75+cMC\n",
71+
"gmt end show\n",
72+
"\"\"\".splitlines()"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"id": "fa313831-3369-4dc3-bb92-6ca7b671dd65",
79+
"metadata": {},
80+
"outputs": [],
81+
"source": [
82+
"import pygmt\n",
83+
"\n",
84+
"fig = pygmt.Figure()\n",
85+
"pygmt.config(FONT_TITLE=\"10p\", MAP_TITLE_OFFSET=\"4p\")\n",
86+
"fig.basemap(region=[0, 20, 0, 3], projection=\"X7.5c/2c\", frame=\"lrtb+tGMT CLI\")\n",
87+
"fig.paragraph(\n",
88+
" x=0.25,\n",
89+
" y=0.6,\n",
90+
" text=gmt_str,\n",
91+
" parwidth=50,\n",
92+
" linespacing=0.25,\n",
93+
" alignment=\"left\",\n",
94+
" justify=\"BL\",\n",
95+
" font=\"Courier-Bold,6p\"\n",
96+
")\n",
97+
"\n",
98+
"fig.shift_origin(xshift=\"w+0.1c\")\n",
99+
"fig.basemap(region=[0, 20, 0, 3], projection=\"X9.25c/2c\", frame=\"lrtb+tPyGMT\")\n",
100+
"fig.paragraph(\n",
101+
" x=0.25,\n",
102+
" y=0.25,\n",
103+
" text=pygmt_str,\n",
104+
" parwidth=50,\n",
105+
" linespacing=0.25,\n",
106+
" alignment=\"left\",\n",
107+
" justify=\"BL\",\n",
108+
" font=\"Courier-Bold,6p\"\n",
109+
")\n",
110+
"fig.show()\n",
111+
"fig.savefig(\"Fig1_PyGMT_GMT_comparison.png\")"
112+
]
113+
}
114+
],
115+
"metadata": {
116+
"kernelspec": {
117+
"display_name": "pygmt",
118+
"language": "python",
119+
"name": "python3"
120+
},
121+
"language_info": {
122+
"codemirror_mode": {
123+
"name": "ipython",
124+
"version": 3
125+
},
126+
"file_extension": ".py",
127+
"mimetype": "text/x-python",
128+
"name": "python",
129+
"nbconvert_exporter": "python",
130+
"pygments_lexer": "ipython3",
131+
"version": "3.12.7"
132+
}
133+
},
134+
"nbformat": 4,
135+
"nbformat_minor": 5
136+
}

0 commit comments

Comments
 (0)