xoa.plot.plot_flow#
- xoa.plot.plot_flow(u, v, duration=None, step=None, particles=None, axes=None, alpha=None, linewidth=None, color=None, 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 (None, int, xarray.Dataset, tuple) – Either a number of particles or a dataset of initial positions with longitude and latitude coordinates. It defaults to the
plot.flow_particlesoption.axes (matplotlib.axes.Axes) – The axes instance
alpha (None, float, tuple) – Alpha transparency. If a tuple, apply a linear alpha ramp to the track from its start to its end. It defaults to the
plot.flow_alphaoption.linewidth (None, float, tuple) – Linewidth of the track. If a tuple, apply a linear linewidth ramp to the track from its start to its end. It defaults to the
plot.flow_linewidthoption.color (None) – Single color for the track, which defaults to the
plot.flow_coloroption.autolim (None, bool) – Whether 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 refers to the
matplotlib.collections.LineCollectioninstance. 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': np.float64(5882.1517364427955), 'duration': np.float64(58821.51736442796), 'linecollection': <matplotlib.collections.LineCollection at 0x738bee4d6710>}