Home > Back-end >  Trouble plotting quivers from netcdf file
Trouble plotting quivers from netcdf file

Time:01-14

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 Only one line of data plotted?

CodePudding user response:

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!

  • Related