113 lines
2.5 KiB
Plaintext
113 lines
2.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Arrows"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"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__ = ['Vector data']"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"def sample_data(shape=(20, 30)):\n",
|
|
" \"\"\"\n",
|
|
" Return ``(x, y, u, v, crs)`` of some vector data\n",
|
|
" computed mathematically. The returned crs will be a rotated\n",
|
|
" pole CRS, meaning that the vectors will be unevenly spaced in\n",
|
|
" regular PlateCarree space.\n",
|
|
"\n",
|
|
" \"\"\"\n",
|
|
" crs = ccrs.RotatedPole(pole_longitude=177.5, pole_latitude=37.5)\n",
|
|
"\n",
|
|
" x = np.linspace(311.9, 391.1, shape[1])\n",
|
|
" y = np.linspace(-23.6, 24.8, shape[0])\n",
|
|
"\n",
|
|
" x2d, y2d = np.meshgrid(x, y)\n",
|
|
" u = 10 * (2 * np.cos(2 * np.deg2rad(x2d) + 3 * np.deg2rad(y2d + 30)) ** 2)\n",
|
|
" v = 20 * np.cos(6 * np.deg2rad(x2d))\n",
|
|
"\n",
|
|
" return x, y, u, v, crs\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def main():\n",
|
|
" fig = plt.figure()\n",
|
|
" ax = fig.add_subplot(1, 1, 1, projection=ccrs.Orthographic(-10, 45))\n",
|
|
"\n",
|
|
" ax.add_feature(cfeature.OCEAN, zorder=0)\n",
|
|
" ax.add_feature(cfeature.LAND, zorder=0, edgecolor='black')\n",
|
|
"\n",
|
|
" ax.set_global()\n",
|
|
" ax.gridlines()\n",
|
|
"\n",
|
|
" x, y, u, v, vector_crs = sample_data()\n",
|
|
" ax.quiver(x, y, u, v, transform=vector_crs)\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": 4
|
|
}
|