Skip to content

Commit 2a724e5

Browse files
michaelgrundactions-botyvonnefroehlichweiji14
authored
Create gallery example to show usage of tile maps (#2585)
Co-authored-by: actions-bot <[email protected]> Co-authored-by: Yvonne Fröhlich <[email protected]> Co-authored-by: Wei Ji <[email protected]>
1 parent 6244cad commit 2a724e5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

examples/gallery/maps/tilemaps.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Tile maps
3+
---------
4+
The :meth:`pygmt.Figure.tilemap` method allows to plot
5+
tiles from a tile server or local file as a basemap or overlay.
6+
"""
7+
import contextily
8+
import pygmt
9+
10+
fig = pygmt.Figure()
11+
fig.tilemap(
12+
region=[-157.84, -157.8, 21.255, 21.285],
13+
projection="M12c",
14+
# Set level of details (0-22)
15+
# Higher levels mean a zoom level closer to the Earth's
16+
# surface with more tiles covering a smaller
17+
# geographic area and thus more details and vice versa
18+
# Please note, not all zoom levels are always available
19+
zoom=14,
20+
# Use tiles from OpenStreetMap tile server
21+
source="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
22+
frame="afg",
23+
)
24+
25+
fig.show()
26+
27+
###############################################################################
28+
# It's also possible to use tiles provided via the
29+
# `contextily <https://github.com/geopandas/contextily>`__
30+
# library. See :doc:`Contextily providers <contextily:providers_deepdive>`
31+
# for a list of possible tilemap options.
32+
33+
fig = pygmt.Figure()
34+
fig.tilemap(
35+
region=[-157.84, -157.8, 21.255, 21.285],
36+
projection="M12c",
37+
# Use the Stamen.Watercolor option from contextily
38+
source=contextily.providers.Stamen.Watercolor,
39+
frame="afg",
40+
)
41+
42+
fig.show()

0 commit comments

Comments
 (0)