Skip to content

Commit 17d0734

Browse files
committed
Ensure that plot is clipped to bounding box region when no_clip is False
Pass the region to the grdimage call so that the plot extent is the same as the bounding box region. Set `no_clip=True` to prevent the clipping from happening (i.e., the plot will extend out from the region of interest). Added a unit test checking results for both no_clip True/False, and updated some previous baseline images that have changed slightly.
1 parent 9158c09 commit 17d0734

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

pygmt/src/tilemap.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ def tilemap(
142142
raster = raster.rio.reproject(dst_crs="OGC:CRS84")
143143
raster.gmt.gtype = 1 # set to geographic type
144144

145+
# Only set region if no_clip is False, so that plot is clipped to exact
146+
# bounding box region
147+
if not kwargs.get("N"):
148+
kwargs["R"] = "/".join(str(coordinate) for coordinate in region)
149+
145150
with GMTTempFile(suffix=".tif") as tmpfile:
146151
raster.rio.to_raster(raster_path=tmpfile.name)
147152
with Session() as lib:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
outs:
2+
- md5: 9317080021b0ce6f3b9ea6d17feece00
3+
size: 23275
4+
path: test_tilemap_no_clip_False.png
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
outs:
2+
- md5: 83e6119b2351f9d472ca7e3cc45388c3
3+
size: 60984
4+
path: test_tilemap_no_clip_True.png
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
outs:
2-
- md5: cc40d807da1218cd440dd8655f5f57fb
3-
size: 56875
2+
- md5: 3de0555d86aca49b92425c8d5272a934
3+
size: 59286
44
path: test_tilemap_ogc_wgs84.png
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
outs:
2-
- md5: ea1fc9d829e8534aed7dac825ea0ddff
3-
size: 123201
2+
- md5: a76d9a9a1890d6b1345305eaea598bc3
3+
size: 122195
44
path: test_tilemap_web_mercator.png

pygmt/tests/test_tilemap.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,21 @@ def test_tilemap_ogc_wgs84():
3838
verbose=True,
3939
)
4040
return fig
41+
42+
43+
@pytest.mark.mpl_image_compare
44+
@pytest.mark.parametrize("no_clip", [False, True])
45+
def test_tilemap_no_clip(no_clip):
46+
"""
47+
Create a tilemap plot clipped to the Southern Hemisphere when no_clip is
48+
False, but for the whole globe when no_clip is True.
49+
"""
50+
fig = Figure()
51+
fig.tilemap(
52+
region=[-180.0, 180.0, -90, 0.6886],
53+
zoom=0,
54+
frame="afg",
55+
projection="H180/5c",
56+
no_clip=no_clip,
57+
)
58+
return fig

0 commit comments

Comments
 (0)