#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Nov 22 14:04:14 2017 @author: dandrea """ import matplotlib.pyplot as plt import numpy as np import cartopy.crs as ccrs def cylmap(lat,lon,field, *args, **kwargs): ''' Plots a contour map of the array in "field" over a map of the Earth with coastlines and latitude longitude grid. Contours are couloured and filled, a colorbar is shown. "lat" and "lon" are vectors specifying the latitude and longitude of the map. They must have dimensions compatible with "field". Optional parameters: levels : array_like an array containing the contour levels for the map, default is nlev levels between the minimum and the maximum of field nlev : int number of levels, default 10, if levels is specified, nlev is overridden title : str plot title, default "no title" ''' title = kwargs.get('title',"") nlev = kwargs.get('nlev',10) plt.figure(figsize=(10, 8)) ax = plt.axes(projection=ccrs.PlateCarree()) ax.set_extent([lon[1], lon[-1], lat[1], lat[-1]], crs=ccrs.PlateCarree()) ax.coastlines() ax.gridlines() x,y=np.meshgrid(lon, lat) lev=(np.linspace((field.min()), (field.max()),nlev)) # DEFAULT LEVELS lev = kwargs.get('levels',lev) plt.contourf(x,y,field,transform=ccrs.PlateCarree(),cmap=plt.cm.jet, levels=lev) plt.colorbar(shrink=.5) # draw colorbar plt.contour(x,y,field,transform=ccrs.PlateCarree(),colors='k', levels=lev) if title : plt.title(title)