Skip to content

Commit dcefacd

Browse files
jorisvandenbosschedarribas
authored andcommitted
API: change add_basemap to not return the received ax object (#92)
add_basemap return None instead of ax
1 parent fcf341e commit dcefacd

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

contextily/plotting.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ def add_basemap(
7676
**extra_imshow_args : dict
7777
Other parameters to be passed to `imshow`.
7878
79-
Returns
80-
-------
81-
ax : AxesSubplot
82-
Matplotlib axis with `x_lim` and `y_lim` set in Web
83-
Mercator (EPSG=3857) containing the basemap
84-
8579
Example
8680
-------
8781
@@ -91,15 +85,15 @@ def add_basemap(
9185
Add a web basemap:
9286
9387
>>> ax = db.plot(alpha=0.5, color='k', figsize=(6, 6))
94-
>>> ax = ctx.add_basemap(ax, url=url)
88+
>>> ctx.add_basemap(ax, url=url)
9589
>>> plt.show()
9690
9791
Or download a basemap to a local file and then plot it:
9892
9993
>>> url = 'virginia.tiff'
10094
>>> _ = ctx.bounds2raster(*db.total_bounds, zoom=6, path=url)
10195
>>> ax = db.plot(alpha=0.5, color='k', figsize=(6, 6))
102-
>>> ax = ctx.add_basemap(ax, url=url)
96+
>>> ctx.add_basemap(ax, url=url)
10397
>>> plt.show()
10498
10599
"""
@@ -144,7 +138,9 @@ def add_basemap(
144138
bb = raster.bounds
145139
extent = bb.left, bb.right, bb.bottom, bb.top
146140
# Plotting
147-
ax.imshow(image, extent=extent, interpolation=interpolation, **extra_imshow_args)
141+
img = ax.imshow(
142+
image, extent=extent, interpolation=interpolation, **extra_imshow_args
143+
)
148144

149145
if reset_extent:
150146
ax.axis((xmin, xmax, ymin, ymax))
@@ -157,7 +153,7 @@ def add_basemap(
157153
if attribution:
158154
add_attribution(ax, attribution, font_size=attribution_size)
159155

160-
return ax
156+
return
161157

162158

163159
def _reproj_bb(left, right, bottom, top, s_crs, t_crs):

tests/test_ctx.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def test_add_basemap():
241241
fig, ax = matplotlib.pyplot.subplots(1)
242242
ax.set_xlim(x1, x2)
243243
ax.set_ylim(y1, y2)
244-
ax = ctx.add_basemap(ax, zoom=10)
244+
ctx.add_basemap(ax, zoom=10)
245245

246246
# ensure add_basemap did not change the axis limits of ax
247247
ax_extent = (x1, x2, y1, y2)
@@ -256,7 +256,7 @@ def test_add_basemap():
256256
ax.set_xlim(x1, x2)
257257
ax.set_ylim(y1, y2)
258258
loc = ctx.Place(SEARCH, path="./test2.tif", zoom_adjust=ADJUST)
259-
ax = ctx.add_basemap(ax, url="./test2.tif")
259+
ctx.add_basemap(ax, url="./test2.tif")
260260

261261
raster_extent = (
262262
-11740803.981631357,
@@ -273,7 +273,7 @@ def test_add_basemap():
273273
f, ax = matplotlib.pyplot.subplots(1)
274274
ax.set_xlim(x1, x2)
275275
ax.set_ylim(y1, y2)
276-
ax = ctx.add_basemap(ax, zoom="auto")
276+
ctx.add_basemap(ax, zoom="auto")
277277

278278
ax_extent = (
279279
-11740727.544603072,
@@ -292,7 +292,7 @@ def test_add_basemap():
292292
f, ax = matplotlib.pyplot.subplots(1)
293293
ax.set_xlim(x1, x2)
294294
ax.set_ylim(y1, y2)
295-
ax = ctx.add_basemap(ax, crs={"init": "epsg:4326"}, attribution=None)
295+
ctx.add_basemap(ax, crs={"init": "epsg:4326"}, attribution=None)
296296
assert ax.get_xlim() == (x1, x2)
297297
assert ax.get_ylim() == (y1, y2)
298298
assert ax.images[0].get_array().sum() == 724238693
@@ -303,9 +303,7 @@ def test_add_basemap():
303303
f, ax = matplotlib.pyplot.subplots(1)
304304
ax.set_xlim(x1, x2)
305305
ax.set_ylim(y1, y2)
306-
ax = ctx.add_basemap(
307-
ax, url="./test2.tif", crs={"init": "epsg:4326"}, attribution=None
308-
)
306+
ctx.add_basemap(ax, url="./test2.tif", crs={"init": "epsg:4326"}, attribution=None)
309307
assert ax.get_xlim() == (x1, x2)
310308
assert ax.get_ylim() == (y1, y2)
311309
assert ax.images[0].get_array().sum() == 724238693

0 commit comments

Comments
 (0)