109 lines
3.1 KiB
Plaintext
109 lines
3.1 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Map tile acquisition\n",
|
|
"--------------------\n",
|
|
"\n",
|
|
"Demonstrates cartopy's ability to draw map tiles which are downloaded on\n",
|
|
"demand from the Stamen tile server. Internally these tiles are then combined\n",
|
|
"into a single image and displayed in the cartopy GeoAxes."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import matplotlib.pyplot as plt\n",
|
|
"from matplotlib.transforms import offset_copy\n",
|
|
"\n",
|
|
"import cartopy.crs as ccrs\n",
|
|
"import cartopy.io.img_tiles as cimgt"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"\n",
|
|
"def main():\n",
|
|
" # Create a Stamen terrain background instance.\n",
|
|
" stamen_terrain = cimgt.Stamen('terrain-background')\n",
|
|
"\n",
|
|
" fig = plt.figure()\n",
|
|
"\n",
|
|
" # Create a GeoAxes in the tile's projection.\n",
|
|
" ax = fig.add_subplot(1, 1, 1, projection=stamen_terrain.crs)\n",
|
|
"\n",
|
|
" # Limit the extent of the map to a small longitude/latitude range.\n",
|
|
" ax.set_extent([-22, -15, 63, 65], crs=ccrs.Geodetic())\n",
|
|
"\n",
|
|
" # Add the Stamen data at zoom level 8.\n",
|
|
" ax.add_image(stamen_terrain, 8)\n",
|
|
"\n",
|
|
" # Add a marker for the Eyjafjallajökull volcano.\n",
|
|
" ax.plot(-19.613333, 63.62, marker='o', color='red', markersize=12,\n",
|
|
" alpha=0.7, transform=ccrs.Geodetic())\n",
|
|
"\n",
|
|
" # Use the cartopy interface to create a matplotlib transform object\n",
|
|
" # for the Geodetic coordinate system. We will use this along with\n",
|
|
" # matplotlib's offset_copy function to define a coordinate system which\n",
|
|
" # translates the text by 25 pixels to the left.\n",
|
|
" geodetic_transform = ccrs.Geodetic()._as_mpl_transform(ax)\n",
|
|
" text_transform = offset_copy(geodetic_transform, units='dots', x=-25)\n",
|
|
"\n",
|
|
" # Add text 25 pixels to the left of the volcano.\n",
|
|
" ax.text(-19.613333, 63.62, u'Eyjafjallajökull',\n",
|
|
" verticalalignment='center', horizontalalignment='right',\n",
|
|
" transform=text_transform,\n",
|
|
" bbox=dict(facecolor='sandybrown', alpha=0.5, boxstyle='round'))\n",
|
|
" plt.show()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"main()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.8.5"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|