# Note that when we extract ``u`` and ``v`` from the file, # we only read every third latitude and longitude. # This choice was made because ``geocat.viz`` doesn't offer an # equivalent function to ncl's ``vcMinDistanceF`` yet. file_in = xr.open_dataset('../../data/netcdf_files/uv300.nc') # Our dataset is a subset of the data from the file ds = file_in.isel(time=1, lon=slice(0, -1, 3), lat=slice(1, -1, 3)) ############################################################################### # Make the plot # Set up figure and axes fig, ax = plt.subplots(figsize=(10, 5.25)) ax = plt.axes(projection=ccrs.PlateCarree()) nclize_axis(ax) add_lat_lon_ticklabels(ax) # Set major and minor ticks plt.xticks(range(-180, 181, 30)) plt.yticks(range(-90, 91, 30)) # Draw vector plot # Notes # 1. We plot every third vector in each direction, which is not as nice as vcMinDistanceF in NCL # 2. There is no matplotlib equivalent to "CurlyVector" Q = plt.quiver(ds['lon'], ds['lat'], ds['U'].data, ds['V'].data, color='black',
lat_sst = sst['lat'] lon_sst = sst['lon'] lat_uv = u['lat'] lon_uv = u['lon'] ############################################################################### # Make the plot # Define levels for contour map # Levels are [24, 24.1, ..., 28.8, 28.9] levels = np.linspace(24, 28.9, 50) # Set up figure fig, ax = plt.subplots(figsize=(10, 7)) ax = plt.axes(projection=ccrs.PlateCarree()) nclize_axis(ax, minor_per_major=5) add_lat_lon_ticklabels(ax) # Set major and minor ticks plt.xlim([65, 95]) plt.ylim([5, 25]) plt.xticks(range(70, 95, 10)) plt.yticks(range(5, 27, 5)) # Draw vector plot Q = plt.quiver(lon_uv, lat_uv, u, v, color='white', pivot='middle',
import numpy as np import xarray as xr import geocat.datafiles from geocat.viz.util import nclize_axis ################################################################################ # Open data file and extract a slice of the data dset = xr.open_dataset(geocat.datafiles.get("netcdf_files/TestData.xy3.nc")) ds = dset.isel(case=0, time=slice(0, 36)) ################################################################################ # Create XY plot with two different Y axes fig, ax1 = plt.subplots(figsize=(12, 8)) nclize_axis(ax1) ax1.set_xlabel(ds.time.long_name, fontsize=24) ax1.set_ylabel(f"{ds.T.long_name} [solid]", fontsize=24) ax1.plot(ds.time, ds.T, color="blue", linestyle="-", linewidth=2.0) ax1.tick_params(axis="both", labelsize=20) ax1.set_xlim(xmin=1970, xmax=1973) ax1.set_ylim(ymin=0.0, ymax=16.0) ax1.set_yticks(np.arange(0, 17, 3)) ax2 = ax1.twinx() nclize_axis(ax2) # we already handled the x-label with ax1 ax2.set_ylabel(f"{ds.P.long_name} [dash]", fontsize=24) ax2.plot(ds.time,
# now draw arrows # xarray doesn't have a quiver method (yet) # the NCL code plots every 4th value in lat, lon # this is the equivalent of u(::4, ::4) subset = ds.isel(lat=slice(None, None, 4), lon=slice(None, None, 4)) ax[2].quiver( subset.lon, subset.lat, subset.U, subset.V, width=0.0015, # thinner than default transform=ccrs.PlateCarree(), zorder=2, # hack to make sure quiver plots on top of continents scale=1100, # adjust till it looks right ) ax[2].set_title("Vector Wind", loc="left", y=1.05) # cartopy axes require this to be manual ax[2].set_xticks(kwargs["xticks"]) ax[2].set_yticks(kwargs["yticks"]) # make axes look nice and add coastlines [nclize_axis(axes) for axes in ax.flat] [add_lat_lon_ticklabels(axes) for axes in ax.flat] # nice figure size in inches f.set_size_inches((5, 8)) plt.show()