{ "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", "\n", "from cartopy import crs\n", "from geoviews import opts\n", "\n", "gv.extension('bokeh')" ] }, { "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=crs.PlateCarree(central_longitude=180))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(contours * gf.coastline).opts(\n", " opts.FilledContours(levels=8, color_levels=10, cmap='nipy_spectral',\n", " colorbar=True, width=600, height=300, projection=crs.Mollweide()))" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }