From aa971d15896e5a585dbd9f424c79c199007f45c5 Mon Sep 17 00:00:00 2001 From: "Morten W. Hansen" Date: Mon, 15 Apr 2024 09:00:47 +0200 Subject: [PATCH] improve quiver plot --- swutils/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/swutils/utils.py b/swutils/utils.py index 4566b72..43cac4a 100644 --- a/swutils/utils.py +++ b/swutils/utils.py @@ -25,11 +25,18 @@ def plot_wind_map(w, vmin=0, vmax=20, title=None): mlon, mlat = w.get_geolocation_grids() da = xr.DataArray(np.sqrt(np.square(w['U']) + np.square(w['V'])), dims=["y", "x"], coords={"lat": (("y", "x"), mlat), "lon": (("y", "x"), mlon)}) - da.plot.pcolormesh("lon", "lat", ax=ax1, vmin=vmin, vmax=vmax, cmap=cmocean.cm.balance, + dp = 15 + du = xr.DataArray(w['U'][::dp,::dp], dims=["y", "x"], + coords={"lat": (("y", "x"), mlat[::dp,::dp]), "lon": (("y", "x"), mlon[::dp,::dp])}) + dv = xr.DataArray(w['V'][::dp,::dp], dims=["y", "x"], + coords={"lat": (("y", "x"), mlat[::dp,::dp]), "lon": (("y", "x"), mlon[::dp,::dp])}) + ds = xr.Dataset({"du": du, "dv": dv}) + + da.plot.pcolormesh("lon", "lat", ax=ax1, vmin=vmin, vmax=vmax, cmap=cmocean.cm.speed, add_colorbar=cb) #ds = xr.open_dataset(w.filename) #ds.assign_coords({"lat": (("y", "x"), mlat), "lon": (("y", "x"), mlon)}) - #ds.plot.quiver(x="lon", y="lat", u="U", v="V", ax=ax1) + ds.plot.quiver(x="lon", y="lat", u="du", v="dv", ax=ax1, angles="xy", headwidth=2, width=0.001) cb = False ax1.coastlines() ax1.gridlines(draw_labels=True)