#!/usr/bin/env python # coding: utf-8 # In[1]: from datetime import datetime import cartopy.crs as ccrs import cartopy.feature as cfeature import matplotlib.pyplot as plt import metpy.calc as mpcalc from metpy.units import units import numpy as np from scipy.ndimage import gaussian_filter import xarray as xr # In[2]: ds = xr.open_dataset('https://thredds.ucar.edu/thredds/dodsC/casestudies/' 'python-gallery/NAM_20161031_1200.nc') ds.coords # In[4]: # Set up the projection that will be used for plotting mapcrs = ccrs.LambertConformal(central_longitude=-100, central_latitude=35, standard_parallels=(30, 60)) # Set up the projection of the data; if lat/lon then PlateCarree is what you want datacrs = ccrs.PlateCarree() # Start the figure and create plot axes with proper projection fig = plt.figure(1, figsize=(14, 12)) ax = plt.subplot(111, projection=mapcrs) ax.set_extent([-130, -72, 20, 55], ccrs.PlateCarree()) # Add geopolitical boundaries for map reference ax.add_feature(cfeature.COASTLINE.with_scale('50m')) ax.add_feature(cfeature.STATES.with_scale('50m')) # Plot 500-hPa Colorfill Wind Speeds in knots clevs_500_sped = np.arange(30, 150, 20) cf = ax.contourf(lons, lats, sped_500, clevs_500_sped, cmap=plt.cm.BuPu, transform=datacrs) plt.colorbar(cf, orientation='horizontal', pad=0, aspect=50) # Plot 500-hPa Geopotential Heights in meters clevs_500_hght = np.arange(0, 8000, 60) cs = ax.contour(lons, lats, hght_500, clevs_500_hght, colors='black', transform=datacrs) plt.clabel(cs, fmt='%d') # Plot 500-hPa wind barbs in knots, regrid to reduce number of barbs ax.barbs(lons, lats, uwnd_500.to('kt').m, vwnd_500.to('kt').m, pivot='middle', color='black', regrid_shape=20, transform=datacrs) # Make some nice titles for the plot (one right, one left) plt.title('500-hPa NAM Geopotential Heights (m), Wind Speed (kt),' ' and Wind Barbs (kt)', loc='left') plt.title('Valid Time: {}'.format(vtime), loc='right') # Adjust image and show plt.subplots_adjust(bottom=0, top=1) plt.show() # In[ ]: