xoa.plot.plot_flow
- xoa.plot.plot_flow(u, v, duration=None, step=None, particles=2000, axes=None, alpha=(0.2, 1), linewidth=0.3, color='k', autolim=None, **kwargs)[source]
Plot currents as a windy-like plot with random little lagrangian tracks
- Parameters:
u (xarray.DataArray) – Gridded zonal velocity
v (xarray.DataArray) – Gridded meridional velocity
duration (int, numpy.timedelta64) – Total integration time in seconds
step (int, numpy.timedelta64) – Integration step in seconds
particles (int, xarray.Dataset, tuple) – Either a number of particles or a dataset of initial positions with longitude and latitude coordinates
axes (matplotlib.axes.Axes) – The axes instance
alpha (float, tuple) – Alpha transparency. If a tuple, apply a linear alpha ramp to the track from its start to its end.
linewidth (float, tuple) – Linewidth of the track. If a tuple, apply a linear linewidth ramp to the track from its start to its end.
color – Single color for the track.
autolim (None, bool) – Wether to auto-update the data limits. A value of None sets autolim to True if “axes” is not provided, else to None. See
matplotlib.axes.Axes.add_collection()
.
- Returns:
dict – With the following keys: axes, linecollection, step, duration. linecollection refere to the
matplotlib.collections.LineCollection
instance. The duration and step are also stored in the output.
Example
# Setup data In [1]: x = np.linspace(0, 2*np.pi, 20) In [2]: y = np.linspace(0, 2*np.pi, 20) In [3]: X, Y = np.meshgrid(x,y) In [4]: U = np.sin(X) * np.cos(Y) In [5]: V = -np.cos(X) * np.sin(Y) # As a dataset In [6]: ds = xr.Dataset( ...: {"u": (('lat', 'lon'), U), "v": (('lat', 'lon'), V)}, ...: coords={"lat": ("lat", y), "lon": ("lon", x)}) ...: # Plot In [7]: plot_flow(ds["u"], ds["v"]) Out[7]: {'axes': <Axes: >, 'step': 5882.1517364427955, 'duration': 58821.51736442796, 'linecollection': <matplotlib.collections.LineCollection at 0x7f37bd14a7d0>}