Matplotlib is a powerful library, and it can be combined with a number of other powerful Python features. Here I would like to play with the cartopy geographical library, using Ipython notebook and keeping all the images generated inline.
I am going to use two open data sources, one is the MapquestOSM, the other is a source from those in the cartopy gallery of examples. I am going to take a different geographical extent from the cartopy gallery examples and I am going to add a few geographical points plotting them onto the charts in addition.
In order to add a bit of spice, I have defined a custom symbol to plot the known geo points on both images.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
""" Produces maps pulling data from various available sources and adds some augmenting data on top... """ from matplotlib.path import Path import matplotlib.pyplot as plt import numpy as np %matplotlib inline import cartopy.crs as ccrs from cartopy.io.img_tiles import MapQuestOSM def cartopy_matplotlib(): imagery = MapQuestOSM() anac_lon, anac_lat = 14.213700, 40.552690 capri_lon, capri_lat = 14.242840, 40.550472 plt.figure(figsize=(13,13), dpi=100) ax = plt.axes(projection=imagery.crs) ax.set_extent((14.19, 14.27, 40.53, 40.57)) # Add the imagery to the map. ax.add_image(imagery, 14) # Define a custom marker... theta = np.linspace(0, 2 * np.pi, 100) circle_verts = np.vstack([np.sin(theta), np.cos(theta)]).T concentric_circle = Path.make_compound_path(Path(circle_verts[::-1]), Path(circle_verts * 0.6)) plt.plot([anac_lon], [anac_lat], color='green', markersize=10, marker=concentric_circle, transform=ccrs.Geodetic()) plt.plot([capri_lon], [capri_lat], color='green', markersize=10, marker=concentric_circle, transform=ccrs.Geodetic()) plt.title('Capri from MapQuestOSM') plt.show() plt.figure(figsize=(13,13), dpi=100) url = 'http://map1c.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi' layer = 'VIIRS_CityLights_2012' # Data Source ax = plt.axes(projection=ccrs.PlateCarree()) ax.add_wmts(url, layer) ax.set_extent((5.053, 22.72, 36.15, 46.53)) plt.plot([capri_lon], [capri_lat], color='red', markersize=10, marker=concentric_circle, transform=ccrs.Geodetic()) plt.title('Italy by night') plt.show() cartopy_matplotlib() |
The two images here below are the resulting inline figures: