Skip to content

Commit b92ca53

Browse files
Deploy v0.18.0 from b1d4bd7
1 parent a6b427a commit b92ca53

1,549 files changed

Lines changed: 213865 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

latest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.17.0
1+
v0.18.0

v0.18.0/.buildinfo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 97d232196ee9dabadd9f84c065adb402
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n# Scale bar\n\nThe ``map_scale`` parameter of the :meth:`pygmt.Figure.basemap` and\n:meth:`pygmt.Figure.coast` methods is used to add a scale bar to a map.\nThis example shows how such a scale bar can be customized:\n\n - position: **g**\\|\\ **j**\\|\\ **J**\\|\\ **n**\\|\\ **x**. Set the position\n of the reference point. Choose from\n\n - **g**: Give map coordinates as *longitude*\\/\\ *latitude*.\n - **j**\\|\\ **J**: Specify a\n :doc:`2-character justification code </techref/justification_codes>`.\n Lower / uppercase **j** / **J** mean inside / outside of the map\n bounding box.\n - **n**: Give normalized bounding box coordinates as *nx*\\/\\ *ny*.\n - **x**: Give plot coordinates as *x*\\/\\ *y*.\n\n - length: **+w**. Give a distance value, and, optionally a distance unit.\n Choose from **e** (meters), **f** (feet), **k** (kilometers) [Default],\n **M** (statute miles), **n** (nautical miles), or **u** (US survey feet).\n - origin: **+c**\\ [*slon*/]\\ *slat*. Control where on the map the scale bar\n applies. If **+c** is not given the reference point is used. If only\n **+c** is appended the middle of the map is used. Note that *slon* is only\n optional for projections with constant scale along parallels, e.g.,\n Mercator projection.\n - justify: **+j**. Set the anchor point. Specify a\n :doc:`2-character justification code </techref/justification_codes>`.\n - offset: **+o**\\ *offset* or **+o**\\ *xoffset*/\\ *yoffset*. Give either a\n common shift or individual shifts in x- (longitude) and y- (latitude)\n directions.\n - height: Use :gmt-term:`MAP_SCALE_HEIGHT` via :func:`pygmt.config`.\n - fancy style: **+f**. Get a scale bar that looks like train tracks.\n - unit: **+u**. Add the distance unit given via **+w** to the single\n distance values.\n - label: **+l**. Add the distance unit given via **+w** as label. Append\n text to get a customized label instead.\n - alignment: **+a**. Set the label alignment. Choose from **t**\\(op)\n [Default], **b**\\(ottom), **l**\\(eft), or **r**\\(ight).\n"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"collapsed": false
15+
},
16+
"outputs": [],
17+
"source": [
18+
"import pygmt\nfrom pygmt.params import Box\n\n# Create a new Figure instance\nfig = pygmt.Figure()\n\n# Mercator projection with 10 centimeters width\nfig.basemap(region=[-45, -25, -15, 0], projection=\"M0/0/10c\", frame=[\"WSne\", \"af\"])\n\n# -----------------------------------------------------------------------------\n# Top Left: Add a plain scale bar\n# It is placed based on geographic coordinates (g) 42\u00b0 West and 1\u00b0 South,\n# applies at the reference point (+c is not given), and represents a\n# length (+w) of 500 kilometers\nfig.basemap(map_scale=\"g-42/-1+w500k\")\n\n# -----------------------------------------------------------------------------\n# Top Right: Add a fancy scale bar\n# It is placed based on normalized bounding box coordinates (n)\n# Use a fancy style (+f) to get a scale bar that looks like train tracks\n# Add the distance unit (+u) to the single distance values\nfig.basemap(map_scale=\"n0.8/0.95+w500k+f+u\")\n\n# -----------------------------------------------------------------------------\n# Bottom Left: Add a thick scale bar\n# Adjust the GMT default parameter MAP_SCALE_HEIGHT locally (the change applies\n# only to the code within the \"with\" statement)\n# It applies (+c) at the middle of the map (no location is appended to +c)\n# Without appending text, +l adds the distance unit as label\nwith pygmt.config(MAP_SCALE_HEIGHT=\"10p\"):\n fig.basemap(map_scale=\"n0.2/0.15+c+w500k+f+l\")\n\n# -----------------------------------------------------------------------------\n# Bottom Right: Add a scale bar valid for a specific location\n# It is placed at BottomRight (j) using MiddleRight as anchor point (+j) with\n# an offset (+o) of 1 centimeter in both x- and y-directions\n# It applies (+c) at -7\u00b0 South, add a customized label by appending text to +l\nfig.basemap(map_scale=\"jBR+jMR+o1c/1c+c-7+w500k+f+u+lvalid at 7\u00b0 S\")\n\nfig.show()"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"The ``box`` parameter allows surrounding the scale bar. This can be useful\nwhen adding a scale bar to a colorful map. To fill the box, append **+g**\nwith the desired color (or pattern). The outline of the box can be adjusted\nby appending **+p** with the desired thickness, color, and style. To force\nrounded edges append **+r** with the desired radius.\n\n"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {
32+
"collapsed": false
33+
},
34+
"outputs": [],
35+
"source": [
36+
"# Create a new Figure instance\nfig = pygmt.Figure()\n\nfig.coast(\n region=[-45, -25, -15, 0],\n projection=\"M10c\",\n land=\"tan\",\n water=\"steelblue\",\n frame=[\"WSne\", \"af\"],\n # Set the label alignment (+a) to right (r)\n map_scale=\"jBL+o1c/1c+c-7+w500k+f+lkm+ar\",\n # Fill the box in white with a transparency of 30 percent, add a solid\n # outline in darkgray (gray30) with a thickness of 0.5 points, and use\n # rounded edges with a radius of 3 points\n box=Box(fill=\"white@30\", pen=\"0.5p,gray30,solid\", radius=\"3p\"),\n)\n\nfig.show()"
37+
]
38+
}
39+
],
40+
"metadata": {
41+
"kernelspec": {
42+
"display_name": "Python 3",
43+
"language": "python",
44+
"name": "python3"
45+
},
46+
"language_info": {
47+
"codemirror_mode": {
48+
"name": "ipython",
49+
"version": 3
50+
},
51+
"file_extension": ".py",
52+
"mimetype": "text/x-python",
53+
"name": "python",
54+
"nbconvert_exporter": "python",
55+
"pygments_lexer": "ipython3",
56+
"version": "3.14.2"
57+
}
58+
},
59+
"nbformat": 4,
60+
"nbformat_minor": 0
61+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
Bit and hachure patterns
3+
========================
4+
5+
In addition to colors, PyGMT also allows using bit and hachure patterns to fill symbols,
6+
polygons, and other areas, via the ``fill`` parameter or similar parameters.
7+
8+
Example method parameters that support bit and hachure patterns include:
9+
10+
- :meth:`pygmt.Figure.coast`: Land and water masses via ``land`` and ``water``
11+
- :meth:`pygmt.Figure.histogram`: Histogram bars via ``fill``
12+
- :meth:`pygmt.Figure.meca`: Focal mechanisms via ``compression_fill`` and
13+
``extension_fill``
14+
- :meth:`pygmt.Figure.plot`: Symbols and polygons via ``fill``
15+
- :meth:`pygmt.Figure.rose`: Histogram sectors via ``fill``
16+
- :meth:`pygmt.Figure.solar`: Day-light terminators via ``fill``
17+
- :meth:`pygmt.Figure.ternary`: Symbols via ``fill``
18+
- :meth:`pygmt.Figure.velo`: Uncertainty wedges and velocity error ellipses via
19+
``uncertainty_fill``
20+
- :meth:`pygmt.Figure.wiggle`: Anomalies via ``positive_fill`` and ``negative_fill``
21+
22+
GMT provides 90 predefined 1-bit patterns, which are numbered from 1 to 90. In addition,
23+
custom 1-, 8-, or 24-bit image raster files can also be used as patterns.
24+
25+
These patterns can be specified via the :class:`pygmt.params.Pattern` class. The
26+
patterns can be customized with different resolution and different foreground and
27+
background colors. The foreground and background colors can also be inverted.
28+
"""
29+
30+
# %%
31+
import pygmt
32+
from pygmt.params import Pattern
33+
34+
# A list of patterns that will be demonstrated.
35+
# By default, a pattern is plotted in black and white with a resolution of 300 dpi.
36+
patterns = [
37+
# Predefined 1-bit pattern 8.
38+
Pattern(8),
39+
# Predefined 1-bit pattern 19.
40+
Pattern(19),
41+
# Pattern 19 with custom background ("red3") and foreground ("lightbrown").
42+
Pattern(19, bgcolor="red3", fgcolor="lightbrown"),
43+
# Invert the background and foreground.
44+
Pattern(19, invert=True, bgcolor="red3", fgcolor="lightbrown"),
45+
# Same as above, but with a 100 dpi resolution.
46+
Pattern(19, bgcolor="red3", fgcolor="lightbrown", dpi=100),
47+
# Same as above, but with a transparent background by setting bgcolor to "".
48+
Pattern(19, bgcolor="", fgcolor="lightbrown", dpi=100),
49+
]
50+
51+
fig = pygmt.Figure()
52+
fig.basemap(
53+
region=[0, 10, 0, 12],
54+
projection="X18c/10c",
55+
frame="rlbt+glightgray+tBit and Hachure Patterns",
56+
)
57+
y = 11
58+
for pattern in patterns:
59+
# Plot a square with the pattern as fill.
60+
# The square has a size of 2 centimeters with a 1 point thick, black outline.
61+
fig.plot(x=1, y=y, style="s2c", pen="1p,black", fill=pattern)
62+
# Add a description of the pattern.
63+
fig.text(x=2, y=y, text=str(repr(pattern)), font="Courier-Bold", justify="ML")
64+
y -= 2
65+
fig.show()
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
"""
2+
Setting the region
3+
==================
4+
5+
Many of the plotting methods take the ``region`` parameter, which sets the
6+
area that will be shown in the figure. This tutorial covers the different types
7+
of inputs that it can accept.
8+
"""
9+
10+
# %%
11+
import pygmt
12+
13+
# %%
14+
# Coordinates
15+
# -----------
16+
#
17+
# A string of coordinates can be passed to ``region``, in the form of
18+
# *xmin*/*xmax*/*ymin*/*ymax*.
19+
20+
fig = pygmt.Figure()
21+
fig.coast(
22+
# Set the x-range from 10E to 20E and the y-range to 35N to 45N
23+
region="10/20/35/45",
24+
# Set projection to Mercator, and the figure size to 15 centimeters
25+
projection="M15c",
26+
# Set the color of the land to light gray
27+
land="lightgray",
28+
# Set the color of the water to white
29+
water="white",
30+
# Display the national borders and set the pen thickness to 0.5p
31+
borders="1/0.5p",
32+
# Display the shorelines and set the pen thickness to 0.5p
33+
shorelines="1/0.5p",
34+
# Set the frame to display annotations and gridlines
35+
frame="ag",
36+
)
37+
fig.show()
38+
39+
# %%
40+
# The coordinates can be passed to ``region`` as a list, in the form of
41+
# [*xmin*, *xmax*, *ymin*, *ymax*].
42+
43+
fig = pygmt.Figure()
44+
fig.coast(
45+
# Set the x-range from 10E to 20E and the y-range to 35N to 45N
46+
region=[10, 20, 35, 45],
47+
projection="M12c",
48+
land="lightgray",
49+
water="white",
50+
borders="1/0.5p",
51+
shorelines="1/0.5p",
52+
frame="ag",
53+
)
54+
fig.show()
55+
56+
# %%
57+
# Instead of passing axes minima and maxima, the coordinates can be passed for
58+
# the bottom-left and top-right corners. The string format takes the
59+
# coordinates for the bottom-left and top-right coordinates. To specify corner
60+
# coordinates, append **+r** at the end of the ``region`` string.
61+
62+
fig = pygmt.Figure()
63+
fig.coast(
64+
# Set the bottom-left corner as 10E, 35N and the top-right corner as
65+
# 20E, 45N
66+
region="10/35/20/45+r",
67+
projection="M12c",
68+
land="lightgray",
69+
water="white",
70+
borders="1/0.5p",
71+
shorelines="1/0.5p",
72+
frame="ag",
73+
)
74+
fig.show()
75+
76+
77+
# %%
78+
# Global regions
79+
# --------------
80+
#
81+
# In addition to passing coordinates, the argument **d** can be passed to set
82+
# the region to the entire globe. The range is 180W to 180E (-180, 180) and 90S
83+
# to 90N (-90 to 90). With no parameters set for the projection, the figure
84+
# defaults to be centered at the mid-point of both x- and y-axes. Using
85+
# **d**\ , the figure is centered at (0, 0), or the intersection of the equator
86+
# and prime meridian.
87+
88+
fig = pygmt.Figure()
89+
fig.coast(
90+
region="d",
91+
projection="Cyl_stere/12c",
92+
land="darkgray",
93+
water="white",
94+
borders="1/0.5p",
95+
shorelines="1/0.5p",
96+
frame="ag",
97+
)
98+
fig.show()
99+
100+
# %%
101+
# The argument **g** can be passed, which encompasses the entire globe. The
102+
# range is 0E to 360E (0, 360) and 90S to 90N (-90 to 90). With no parameters
103+
# set for the projection, the figure is centered at (180, 0), or the
104+
# intersection of the equator and International Date Line.
105+
106+
fig = pygmt.Figure()
107+
fig.coast(
108+
region="g",
109+
projection="Cyl_stere/12c",
110+
land="darkgray",
111+
water="white",
112+
borders="1/0.5p",
113+
shorelines="1/0.5p",
114+
frame="ag",
115+
)
116+
fig.show()
117+
118+
119+
# %%
120+
# ISO code
121+
# --------
122+
#
123+
# The ``region`` can be set to include a specific area specified by the
124+
# two-character ISO 3166-1 alpha-2 convention
125+
# (for further information: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
126+
127+
fig = pygmt.Figure()
128+
fig.coast(
129+
# Set the figure region to encompass Japan with the ISO code "JP"
130+
region="JP",
131+
projection="M12c",
132+
land="lightgray",
133+
water="white",
134+
borders="1/0.5p",
135+
shorelines="1/0.5p",
136+
frame="ag",
137+
)
138+
fig.show()
139+
140+
# %%
141+
# The area encompassed by the ISO code can be expanded by appending
142+
# **+r**\ *increment* to the ISO code. The *increment* unit is in degrees, and
143+
# if only one value is added it expands the range of the region in all
144+
# directions. Using **+r** expands the final region boundaries to be multiples
145+
# of *increment* .
146+
147+
fig = pygmt.Figure()
148+
fig.coast(
149+
# Expand the region boundaries to be multiples of 3 degrees in all
150+
# directions
151+
region="JP+r3",
152+
projection="M12c",
153+
land="lightgray",
154+
water="white",
155+
borders="1/0.5p",
156+
shorelines="1/0.5p",
157+
frame="ag",
158+
)
159+
fig.show()
160+
161+
# %%
162+
# Instead of expanding the range of the plot uniformly in all directions, two
163+
# values can be passed to expand differently on each axis. The format is
164+
# *xinc*/*yinc*.
165+
166+
fig = pygmt.Figure()
167+
fig.coast(
168+
# Expand the region boundaries to be multiples of 3 degrees on the x-axis
169+
# and 5 degrees on the y-axis.
170+
region="JP+r3/5",
171+
projection="M12c",
172+
land="lightgray",
173+
water="white",
174+
borders="1/0.5p",
175+
shorelines="1/0.5p",
176+
frame="ag",
177+
)
178+
fig.show()
179+
180+
# %%
181+
# Instead of expanding the range of the plot uniformly in all directions, four
182+
# values can be passed to expand differently in each direction.
183+
# The format is *winc*/*einc*/*sinc*/*ninc*, which expands on the west,
184+
# east, south, and north axes.
185+
186+
fig = pygmt.Figure()
187+
fig.coast(
188+
# Expand the region boundaries to be multiples of 3 degrees to the west, 5
189+
# degrees to the east, 7 degrees to the south, and 9 degrees to the north.
190+
region="JP+r3/5/7/9",
191+
projection="M12c",
192+
land="lightgray",
193+
water="white",
194+
borders="1/0.5p",
195+
shorelines="1/0.5p",
196+
frame="ag",
197+
)
198+
fig.show()
199+
200+
# %%
201+
# The ``region`` increment can be appended with **+R**, which adds the
202+
# increment without rounding.
203+
204+
fig = pygmt.Figure()
205+
fig.coast(
206+
# Expand the region setting outside the range of Japan by 3 degrees in all
207+
# directions, without rounding to the nearest increment.
208+
region="JP+R3",
209+
projection="M12c",
210+
land="lightgray",
211+
water="white",
212+
borders="1/0.5p",
213+
shorelines="1/0.5p",
214+
frame="ag",
215+
)
216+
fig.show()
217+
218+
# %%
219+
# The ``region`` increment can be appended with **+e**, which is like **+r**
220+
# and expands the final region boundaries to be multiples of *increment*.
221+
# However, it ensures that the bounding box extends by at least 0.25 times the
222+
# increment.
223+
224+
fig = pygmt.Figure()
225+
fig.coast(
226+
# Expand the region boundaries to be multiples of 3 degrees in all
227+
# directions
228+
region="JP+e3",
229+
projection="M12c",
230+
land="lightgray",
231+
water="white",
232+
borders="1/0.5p",
233+
shorelines="1/0.5p",
234+
frame="ag",
235+
)
236+
fig.show()

0 commit comments

Comments
 (0)