Trouble plotting quivers from netcdf file

Question:

I am trying to plot wind quivers from a NetCDF file, however, I can only plot one line of quivers, straight across the base map, as seen in the image. The code is below. Thank you very much for any help 🙂

data is here, please replace with the onedrive folder, thanks
https://drive.google.com/file/d/160121aFx0Ys6G1jdQZOCT2Ve9eZgOyUy/view?usp=sharing

import xarray as xr
import cartopy.crs as ccrs
import matplotlib.pyplot as plt

data = xr.open_dataset(<Insert google drive file data here>)

data = data.sel(time='2010-04-14T00:00:00.000000000')

X = data.longitude; Y = data.latitude
U = data.u10[200]; V = data.v10[200]

plt.figure()
ax = plt.subplot(111,projection=ccrs.PlateCarree())

ax.quiver(X[::5], Y[::5], U[::5], V[::5],color='green')

plt.show()

I would expect all the quivers to be plotted, so the graph should be full of the green arrows

Currently, this is the plotted image:

Only one line of data plotted?

Asked By: Samuel B

||

Answers:

You are only taking data from the last row with data.u10[200]. Instead for the quiver, make coordinates as 2D arrays and plot for instance every 5 point of the dataset. Here is my solution, I downloaded and saved your data as "exdata.nc".

#!/usr/bin/env ipython
# --------------------
import xarray as xr
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import numpy as np
# --------------------------------------------------------------------
data = xr.open_dataset('exdata.nc')

data = data.sel(time='2010-04-14T00:00:00.000000000')

X = data.longitude; Y = data.latitude
# --------------------------------------------------------------------
XM,YM = np.meshgrid(X,Y)
U = data.u10; V = data.v10
skipx, skipy = 5,5
# ----------------------------------------------------------------
plt.figure(figsize=(12,12))
ax = plt.subplot(111,projection=ccrs.PlateCarree())

ax.quiver(XM[::skipy,::skipx], YM[::skipy,::skipx], U[::skipy,::skipx], V[::skipy,::skipx],color='green')
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.OCEAN)
plt.show()
# ---------------------------------

Hope this helps as an example!

Answered By: msi_gerva