{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import geoviews as gv\n", "import geoviews.feature as gf\n", "import cartopy.crs as ccrs\n", "\n", "gv.extension('matplotlib')\n", "\n", "gv.output(fig='svg', size=200)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def sample_data(shape=(73, 145)):\n", " \"\"\"Returns ``lons``, ``lats`` and ``data`` of some fake data.\"\"\"\n", " nlats, nlons = shape\n", " ys = np.linspace(-np.pi / 2, np.pi / 2, nlats)\n", " xs = np.linspace(0, 2 * np.pi, nlons)\n", " lons, lats = np.meshgrid(xs, ys)\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(ys)\n", " lons = np.rad2deg(xs)\n", " data = wave + mean\n", "\n", " return lons, lats, data\n", "\n", "lons, lats, data = sample_data()\n", "\n", "# Make sure we declare the central longitude\n", "contours = gv.FilledContours((lons, lats, data), crs=ccrs.PlateCarree(central_longitude=180))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "contours.opts(colorbar=True, levels=8, color_levels=10, cmap='nipy_spectral', projection=ccrs.Mollweide()) * gf.coastline" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }