100 lines
2.2 KiB
Plaintext
100 lines
2.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"import numpy as np\n",
|
|
"\n",
|
|
"import cartopy.crs as ccrs"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"def sample_data(shape=(73, 145)):\n",
|
|
" \"\"\"Return ``lons``, ``lats`` and ``data`` of some fake data.\"\"\"\n",
|
|
" nlats, nlons = shape\n",
|
|
" lats = np.linspace(-np.pi / 2, np.pi / 2, nlats)\n",
|
|
" lons = np.linspace(0, 2 * np.pi, nlons)\n",
|
|
" lons, lats = np.meshgrid(lons, lats)\n",
|
|
" wave = 0.75 * (np.sin(2 * lats) ** 8) * np.cos(4 * lons)\n",
|
|
" mean = 0.5 * np.cos(2 * lats) * ((np.sin(2 * lats)) ** 2 + 2)\n",
|
|
"\n",
|
|
" lats = np.rad2deg(lats)\n",
|
|
" lons = np.rad2deg(lons)\n",
|
|
" data = wave + mean\n",
|
|
"\n",
|
|
" return lons, lats, data"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"\n",
|
|
"def main():\n",
|
|
" fig = plt.figure(figsize=(10, 5))\n",
|
|
" ax = fig.add_subplot(1, 1, 1, projection=ccrs.Mollweide())\n",
|
|
"\n",
|
|
" lons, lats, data = sample_data()\n",
|
|
"\n",
|
|
" ax.contourf(lons, lats, data,\n",
|
|
" transform=ccrs.PlateCarree(),\n",
|
|
" cmap='nipy_spectral')\n",
|
|
" ax.coastlines()\n",
|
|
" ax.set_global()\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
|
|
}
|