{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Cartopy: Customizing map decoration\n\nWhen plotting data on a latitude-longitude grid, showvar\nwill add some default components to a Cartopy map. These\ncan be customized in several ways.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pygeode as pyg\nimport numpy as np, pylab as pyl\nfrom cartopy import crs as ccrs\nimport cartopy\n\n# Construct latitude and longitude coordinate system\nlat = pyg.gausslat(40)\nlon = pyg.regularlon(80, origin=-180, repeat_origin=True)\n\n# Generate x and y components of a vector field on this coordinate system\nT = pyg.cos(4*np.pi * lon / 180.) * pyg.exp(-(lat - 40)**2 / (4*10**2))\nT.plotatts['plotname'] = ''\n\npyl.ioff()\n\n# Simply calling showvar will produce a plot using the PlateCarree (cylindrical) projection\n# Set nozero to true to remove the zero contour\nax = pyg.showvar(T, nozero = True)\n\npyl.ion()\nax.render(1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To make this plot more interesting, lets use a Robinson projection.\nWe create a ''map'' dictionary with the name of the projection and any arguments\n(See the list of projections_ available).\n\n%%\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Turn off interactivity\npyl.ioff()\n\n# Build CartopyAxis for a Lambert Conformal projection\nprj = dict(central_longitude=-90.)\nmap = dict(projection = 'Robinson', prj_args = prj)\n\nax = pyg.showvar(T, nozero=True, map = map)\n\npyl.ion()\nax.render(2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As of Cartopy v0.18, the default labeling of the latitude longitude gridlines\nis not very legible, so it is turned off for all projections except PlateCarree and Mercator.\n\nWe can turn them back on using the ''map_decor'' dictionary. This gives some direct\ncontrol over the gridlines and coastlines. See :meth:`cartopy.mpl.geoaxes.GeoAxes.gridlines()`\nand :meth:`cartopy.mpl.geoaxes.GeoAxes.coastlines` for keyword arguments\n\n%%\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Choose custom grid labeling settings\ngl = dict(color = 'C0', linestyle = '-', \\\n draw_labels=True, \\\n x_inline=False, y_inline=False, \\\n top_labels=True, bottom_labels=True, left_labels=True, right_labels=True,\n rotate_labels=False, \\\n xlocs = pyl.MultipleLocator(30), \\\n ylocs = pyl.MultipleLocator(30))\n\n# Set resolution and line style of coastlines\ncl = dict(resolution='110m', color='0.3', linewidth=2)\n\npyl.ioff()\n\n# Create a new plot.\nax = pyg.showvar(T, nozero=True, map = map, mapdecor = dict(gridlines = gl, coastlines = cl))\n\n# Turn on matplotlib interactivity\npyl.ion()\n\n# Produce plot (and use this one for the gallery thumbnail)\n# sphinx_gallery_thumbnail_number = 3\nax.render(3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This gallery shows how to modify the appearance of maps by passing in appropriate\ndictionaries to showvar; another option is to turn off automatic map decorations\nby passing in ''map_decor = False''. See \n:doc:`Add Cartopy Features ` for an example.\n%%\n\n" ] } ], "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.12" } }, "nbformat": 4, "nbformat_minor": 0 }