Debian Codegraph @

examples/plot_map.py

raw symbols SCIP
1 """
2 Downloading and Plotting Maps
3 -----------------------------
4
5 Plotting maps with Contextily.
6
7 Contextily is designed to pull map tile information from the web. In many
8 cases we want to go from a location to a map of that location as quickly
9 as possible. There are two main ways to do this with Contextily.
10
11 Searching for places with text
12 ==============================
13
14 The simplest approach is to search for a location with text. You can do
15 this with the ``Place`` class. This will return an object that contains
16 metadata about the place, such as its bounding box. It will also contain an
17 image of the place.
18 """
19 import numpy as np
20 import matplotlib.pyplot as plt
21 import contextily as cx
22
23 loc = cx.Place("boulder", zoom_adjust=0) # zoom_adjust modifies the auto-zoom
24
25 # Print some metadata
26 for attr in ["w", "s", "e", "n", "place", "zoom", "n_tiles"]:
27 print("{}: {}".format(attr, getattr(loc, attr)))
28
29 # Show the map
30 im1 = loc.im
31
32 fig, axs = plt.subplots(1, 3, figsize=(15, 5))
33 cx.plot_map(loc, ax=axs[0])
34
35 ###############################################################################
36 # The zoom level will be chosen for you by default, though you can specify
37 # this manually as well:
38
39 loc2 = cx.Place("boulder", zoom=11)
40 cx.plot_map(loc2, ax=axs[1])
41
42 ###############################################################################
43 # Downloading tiles from bounds
44 # =============================
45 #
46 # You can also grab tile information directly from a bounding box + zoom level.
47 # This is demoed below:
48
49 im2, bbox = cx.bounds2img(loc.w, loc.s, loc.e, loc.n, zoom=loc.zoom, ll=True)
50 cx.plot_map(im2, bbox, ax=axs[2], title="Boulder, CO")
51
52 plt.show()