#!/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 from mpl_toolkits.basemap import Basemap def cylmap_BM(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" ''' titles = kwargs.get('titl',"") nlev = kwargs.get('nlev',10) # plt.figure(figsize=(10, 8)) # llcrnrlat,llcrnrlon,urcrnrlat,urcrnrlon # are the lat/lon values of the lower left and upper right corners # of the map. # resolution = 'c' means use crude resolution coastlines. m = Basemap(projection='cyl',llcrnrlat=lat[-1],urcrnrlat=lat[0],\ llcrnrlon=lon[0],urcrnrlon=lon[-1],resolution='c') m.drawcoastlines() # m.fillcontinents(color='coral',lake_color='aqua') # draw parallels and meridians. m.drawparallels(np.arange(-90.,91.,30.)) m.drawmeridians(np.arange(-180.,181.,60.)) m.drawmapboundary(fill_color='aqua') if titles : plt.title(titles) x,y=np.meshgrid(lon, lat) lev=(np.linspace((field.min()), (field.max()),nlev)) # DEFAULT LEVELS lev = kwargs.get('levels',lev) m.contourf(x,y,field,levels=lev)