91 lines
2.1 KiB
Plaintext
91 lines
2.1 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Modifying the boundary/neatline of a map in cartopy\n",
|
|
"---------------------------------------------------\n",
|
|
"\n",
|
|
"This example demonstrates how to modify the boundary/neatline\n",
|
|
"of an axes. We construct a star with coordinates in a Plate Carree\n",
|
|
"coordinate system, and use the star as the outline of the map.\n",
|
|
"\n",
|
|
"Notice how changing the projection of the map represents a *projected*\n",
|
|
"star shaped boundary."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import matplotlib.path as mpath\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"\n",
|
|
"import cartopy.crs as ccrs\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def main():\n",
|
|
" fig = plt.figure()\n",
|
|
" ax = fig.add_axes([0, 0, 1, 1], projection=ccrs.PlateCarree())\n",
|
|
" ax.coastlines()\n",
|
|
"\n",
|
|
" # Construct a star in longitudes and latitudes.\n",
|
|
" star_path = mpath.Path.unit_regular_star(5, 0.5)\n",
|
|
" star_path = mpath.Path(star_path.vertices.copy() * 80,\n",
|
|
" star_path.codes.copy())\n",
|
|
"\n",
|
|
" # Use the star as the boundary.\n",
|
|
" ax.set_boundary(star_path, transform=ccrs.PlateCarree())\n",
|
|
"\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
|
|
}
|