OSGeoLive-Notebooks/Cartopy/always circular stereo.ipynb

109 lines
2.9 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Custom Boundary Shape\n",
"\n",
"This example demonstrates how a custom shape geometry may be used\n",
"instead of the projection's default boundary.\n",
"\n",
"In this instance, we define the boundary as a circle in axes coordinates. This means that no matter the extent of the map itself, the boundary will always be a circle.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.path as mpath\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import cartopy.crs as ccrs\n",
"import cartopy.feature as cfeature\n",
"\n",
"__tags__ = ['Lines and polygons']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def main():\n",
" fig = plt.figure(figsize=[10, 5])\n",
" ax1 = fig.add_subplot(1, 2, 1, projection=ccrs.SouthPolarStereo())\n",
" ax2 = fig.add_subplot(1, 2, 2, projection=ccrs.SouthPolarStereo(),\n",
" sharex=ax1, sharey=ax1)\n",
" fig.subplots_adjust(bottom=0.05, top=0.95,\n",
" left=0.04, right=0.95, wspace=0.02)\n",
"\n",
" # Limit the map to -60 degrees latitude and below.\n",
" ax1.set_extent([-180, 180, -90, -60], ccrs.PlateCarree())\n",
"\n",
" ax1.add_feature(cfeature.LAND)\n",
" ax1.add_feature(cfeature.OCEAN)\n",
"\n",
" ax1.gridlines()\n",
" ax2.gridlines()\n",
"\n",
" ax2.add_feature(cfeature.LAND)\n",
" ax2.add_feature(cfeature.OCEAN)\n",
"\n",
" # Compute a circle in axes coordinates, which we can use as a boundary\n",
" # for the map. We can pan/zoom as much as we like - the boundary will be\n",
" # permanently circular.\n",
" theta = np.linspace(0, 2*np.pi, 100)\n",
" center, radius = [0.5, 0.5], 0.5\n",
" verts = np.vstack([np.sin(theta), np.cos(theta)]).T\n",
" circle = mpath.Path(verts * radius + center)\n",
"\n",
" ax2.set_boundary(circle, transform=ax2.transAxes)\n",
"\n",
" plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"main()\n"
]
},
{
"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": 4
}