Skip to content

Commit

Permalink
Fix inconsistency in import alias (#230)
Browse files Browse the repository at this point in the history
* Fix inconsistency in import alias

* remaining changes

---------

Co-authored-by: Martin Fleischmann <martin@martinfleischmann.net>
  • Loading branch information
maxdswain and martinfleis committed Dec 29, 2023
1 parent 224570c commit a8982d2
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 96 deletions.
2 changes: 1 addition & 1 deletion contextily/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def plot(self, ax=None, zoom=ZOOM, interpolation=INTERPOLATION, attribution=None
Examples
--------
>>> lvl = ctx.Place('Liverpool')
>>> lvl = cx.Place('Liverpool')
>>> lvl.plot()
"""
Expand Down
8 changes: 4 additions & 4 deletions contextily/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def add_basemap(
--------
>>> import geopandas
>>> import contextily as ctx
>>> import contextily as cx
>>> db = geopandas.read_file(ps.examples.get_path('virginia.shp'))
Ensure the data is in Spherical Mercator:
Expand All @@ -92,15 +92,15 @@ def add_basemap(
Add a web basemap:
>>> ax = db.plot(alpha=0.5, color='k', figsize=(6, 6))
>>> ctx.add_basemap(ax, source=url)
>>> cx.add_basemap(ax, source=url)
>>> plt.show()
Or download a basemap to a local file and then plot it:
>>> source = 'virginia.tiff'
>>> _ = ctx.bounds2raster(*db.total_bounds, zoom=6, source=source)
>>> _ = cx.bounds2raster(*db.total_bounds, zoom=6, source=source)
>>> ax = db.plot(alpha=0.5, color='k', figsize=(6, 6))
>>> ctx.add_basemap(ax, source=source)
>>> cx.add_basemap(ax, source=source)
>>> plt.show()
"""
Expand Down
14 changes: 7 additions & 7 deletions examples/plot_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"""
import numpy as np
import matplotlib.pyplot as plt
import contextily as ctx
import contextily as cx

loc = ctx.Place("boulder", zoom_adjust=0) # zoom_adjust modifies the auto-zoom
loc = cx.Place("boulder", zoom_adjust=0) # zoom_adjust modifies the auto-zoom

# Print some metadata
for attr in ["w", "s", "e", "n", "place", "zoom", "n_tiles"]:
Expand All @@ -30,14 +30,14 @@
im1 = loc.im

fig, axs = plt.subplots(1, 3, figsize=(15, 5))
ctx.plot_map(loc, ax=axs[0])
cx.plot_map(loc, ax=axs[0])

###############################################################################
# The zoom level will be chosen for you by default, though you can specify
# this manually as well:

loc2 = ctx.Place("boulder", zoom=11)
ctx.plot_map(loc2, ax=axs[1])
loc2 = cx.Place("boulder", zoom=11)
cx.plot_map(loc2, ax=axs[1])

###############################################################################
# Downloading tiles from bounds
Expand All @@ -46,7 +46,7 @@
# You can also grab tile information directly from a bounding box + zoom level.
# This is demoed below:

im2, bbox = ctx.bounds2img(loc.w, loc.s, loc.e, loc.n, zoom=loc.zoom, ll=True)
ctx.plot_map(im2, bbox, ax=axs[2], title="Boulder, CO")
im2, bbox = cx.bounds2img(loc.w, loc.s, loc.e, loc.n, zoom=loc.zoom, ll=True)
cx.plot_map(im2, bbox, ax=axs[2], title="Boulder, CO")

plt.show()
34 changes: 17 additions & 17 deletions notebooks/providers_deepdive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"metadata": {},
"outputs": [],
"source": [
"import contextily as ctx\n",
"import contextily as cx\n",
"import xyzservices.providers as xyz\n",
"\n",
"import matplotlib.pyplot as plt"
Expand Down Expand Up @@ -60,7 +60,7 @@
"source": [
"fig, ax = plt.subplots(figsize=(8, 8))\n",
"ax.axis(extent)\n",
"ctx.add_basemap(ax)"
"cx.add_basemap(ax)"
]
},
{
Expand Down Expand Up @@ -91,7 +91,7 @@
"source": [
"fig, ax = plt.subplots(figsize=(8, 8))\n",
"ax.axis(extent)\n",
"ctx.add_basemap(ax, source=ctx.providers.CartoDB.Positron)"
"cx.add_basemap(ax, source=cx.providers.CartoDB.Positron)"
]
},
{
Expand Down Expand Up @@ -120,14 +120,14 @@
"source": [
"fig, ax = plt.subplots(figsize=(8, 8))\n",
"ax.axis(extent)\n",
"ctx.add_basemap(ax, source=ctx.providers.OpenStreetMap.Mapnik)"
"cx.add_basemap(ax, source=cx.providers.OpenStreetMap.Mapnik)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Passing `source=ctx.providers.OpenStreetMap.Mapnik` is exactly the same as using `xyzservices` directly - `source=xyz.OpenStreetMap.Mapnik`. Under the hood, `contextily.providers` just wraps `xyzservices.providers`."
"Passing `source=cx.providers.OpenStreetMap.Mapnik` is exactly the same as using `xyzservices` directly - `source=xyz.OpenStreetMap.Mapnik`. Under the hood, `contextily.providers` just wraps `xyzservices.providers`."
]
},
{
Expand All @@ -149,7 +149,7 @@
"source": [
"fig, ax = plt.subplots(figsize=(8, 8))\n",
"ax.axis(extent)\n",
"ctx.add_basemap(ax, source=xyz.OpenStreetMap.Mapnik)"
"cx.add_basemap(ax, source=xyz.OpenStreetMap.Mapnik)"
]
},
{
Expand Down Expand Up @@ -18639,7 +18639,7 @@
}
],
"source": [
"ctx.providers"
"cx.providers"
]
},
{
Expand Down Expand Up @@ -18997,7 +18997,7 @@
}
],
"source": [
"ctx.providers.OpenStreetMap"
"cx.providers.OpenStreetMap"
]
},
{
Expand All @@ -19024,7 +19024,7 @@
}
],
"source": [
"type(ctx.providers.OpenStreetMap.Mapnik)"
"type(cx.providers.OpenStreetMap.Mapnik)"
]
},
{
Expand Down Expand Up @@ -19189,7 +19189,7 @@
}
],
"source": [
"ctx.providers.OpenStreetMap.Mapnik"
"cx.providers.OpenStreetMap.Mapnik"
]
},
{
Expand Down Expand Up @@ -19373,7 +19373,7 @@
}
],
"source": [
"ctx.providers.OpenWeatherMap.Clouds"
"cx.providers.OpenWeatherMap.Clouds"
]
},
{
Expand Down Expand Up @@ -19541,7 +19541,7 @@
}
],
"source": [
"ctx.providers.OpenWeatherMap.Clouds(apiKey=\"my-private-api-key\")"
"cx.providers.OpenWeatherMap.Clouds(apiKey=\"my-private-api-key\")"
]
},
{
Expand All @@ -19551,7 +19551,7 @@
"This can then be specified where a `source` is expected. For example:\n",
" \n",
"```python\n",
"ctx.add_basemap(ax, source=ctx.providers.OpenWeatherMap.Clouds(apiKey=\"my-private-api-key\"))\n",
"cx.add_basemap(ax, source=cx.providers.OpenWeatherMap.Clouds(apiKey=\"my-private-api-key\"))\n",
"```\n"
]
},
Expand Down Expand Up @@ -19588,8 +19588,8 @@
"source": [
"fig, ax = plt.subplots(figsize=(8, 8))\n",
"ax.axis(extent)\n",
"# using the url from `ctx.providers.OpenStreetMap.HOT` as example\n",
"ctx.add_basemap(ax, source='https://a.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png')"
"# using the url from `cx.providers.OpenStreetMap.HOT` as example\n",
"cx.add_basemap(ax, source='https://a.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png')"
]
},
{
Expand Down Expand Up @@ -19619,7 +19619,7 @@
"metadata": {},
"outputs": [],
"source": [
"providers = ctx.providers.flatten()"
"providers = cx.providers.flatten()"
]
},
{
Expand Down Expand Up @@ -19696,7 +19696,7 @@
"axs = axs.flatten()\n",
"for name, ax in zip(selection, axs):\n",
" ax.axis(extent)\n",
" ctx.add_basemap(ax, source=providers[name])\n",
" cx.add_basemap(ax, source=providers[name])\n",
" ax.set_title(name)\n",
" ax.set_axis_off()\n",
"plt.show()\n",
Expand Down
18 changes: 9 additions & 9 deletions notebooks/working_with_local_files.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"source": [
"%matplotlib inline\n",
"\n",
"import contextily as ctx\n",
"import contextily as cx\n",
"import geopandas\n",
"import rasterio\n",
"from rasterio.plot import show as rioshow\n",
Expand Down Expand Up @@ -90,7 +90,7 @@
],
"source": [
"ax = cliwoc.plot(linewidth=0.01, alpha=0.5, color=\"k\")\n",
"ctx.add_basemap(ax, \n",
"cx.add_basemap(ax, \n",
" crs=cliwoc.crs,\n",
" )"
]
Expand Down Expand Up @@ -145,7 +145,7 @@
"metadata": {},
"outputs": [],
"source": [
"img, ext = ctx.bounds2raster(west, \n",
"img, ext = cx.bounds2raster(west, \n",
" south, \n",
" east, \n",
" north, \n",
Expand Down Expand Up @@ -227,7 +227,7 @@
}
],
"source": [
"cape_town = ctx.Place(\"Cape Town\", source=ctx.providers.OpenStreetMap.Mapnik)\n",
"cape_town = cx.Place(\"Cape Town\", source=cx.providers.OpenStreetMap.Mapnik)\n",
"cape_town.plot()"
]
},
Expand All @@ -244,7 +244,7 @@
"metadata": {},
"outputs": [],
"source": [
"cape_town = ctx.Place(\"Cape Town\", source=ctx.providers.OpenStreetMap.Mapnik, path=\"cape_town.tif\")"
"cape_town = cx.Place(\"Cape Town\", source=cx.providers.OpenStreetMap.Mapnik, path=\"cape_town.tif\")"
]
},
{
Expand Down Expand Up @@ -454,7 +454,7 @@
],
"source": [
"ax = cliwoc_cape_town.plot(linewidth=0.05, color=\"k\")\n",
"ctx.add_basemap(ax, \n",
"cx.add_basemap(ax, \n",
" crs=cliwoc_cape_town.crs, \n",
" source=\"cape_town.tif\"\n",
" )"
Expand Down Expand Up @@ -487,7 +487,7 @@
],
"source": [
"ax = cliwoc_cape_town.plot(linewidth=0.05, color=\"k\")\n",
"ctx.add_basemap(ax, \n",
"cx.add_basemap(ax, \n",
" crs=cliwoc_cape_town.crs, \n",
" source=\"cape_town.tif\",\n",
" alpha=0.5\n",
Expand Down Expand Up @@ -521,7 +521,7 @@
],
"source": [
"ax = cliwoc_cape_town_buffer.plot(linewidth=1, color=\"k\")\n",
"ctx.add_basemap(ax, \n",
"cx.add_basemap(ax, \n",
" crs=cliwoc_cape_town.crs, \n",
" source=\"cape_town.tif\"\n",
" )"
Expand Down Expand Up @@ -552,7 +552,7 @@
],
"source": [
"ax = cliwoc_cape_town_buffer.plot(linewidth=1, color=\"k\")\n",
"ctx.add_basemap(ax, \n",
"cx.add_basemap(ax, \n",
" crs=cliwoc_cape_town.crs, \n",
" source=\"cape_town.tif\",\n",
" reset_extent=False\n",
Expand Down

0 comments on commit a8982d2

Please sign in to comment.