stat_streamline ¶
stat_streamline(
mapping: FeatureSpec | None = None,
*,
data: PlotData | None = None,
geom: str | None = None,
position: Position | None = None,
show_legend: bool | None = None,
inherit_aes: bool | None = None,
sampling: Sampling | None = None,
tooltips: Tooltips | None = None,
density: Number | tuple[Number, Number] | None = None,
minlength: Number | None = None,
maxlength: Number | None = None,
integration_direction: Literal | None = None,
broken_streamlines: bool | None = None,
gridded: bool | None = None,
grid_density: Number | None = None,
smooth: Number | None = None,
n_neighbors: int | None = None,
min_mass: Number | None = None,
cutoff_percentile: Number | None = None,
na_rm: bool | None = None,
**other_args: Any,
) -> LayerSpec
Streamlines of a vector field (stat="streamline"), drawn by geom.
As stat_streamline in the R package metR. Every streamline is its own
group of x, y vertices in order; see geom_streamline for how the
field is built and the options.
Parameters:
-
mapping(FeatureSpec, default:None) –Aesthetic mapping from
aes(). Needsx,y,uandv. -
data(DataFrame or dict, default:None) –Layer data; inherits the plot data when None.
-
geom(str, default:"streamline") –Geom that draws the lines, e.g.
"path"(witharrow=arrow()for heads at the line ends) or"point"for the vertices. -
position(str or FeatureSpec, default:None) –Position adjustment, applied to the line vertices.
-
show_legend(bool, default:None) –False hides this layer from the legend.
-
inherit_aes(bool, default:None) –False ignores the plot's default mapping for this layer.
-
sampling((str, int or FeatureSpec), default:None) –Rows to draw: a
sampling_*()spec, an intn(sampling_random(n)) or"none". Default: every row. -
tooltips(FeatureSpec or list of str, default:None) –Tooltip content:
layer_tooltips(), a list of column names, or"none". -
density(float or tuple of float, default:1) –Closeness of the lines (see
geom_streamline). -
minlength(float, default:0.1) –Shortest line kept, in axes coordinates.
-
maxlength(float, default:4.0) –Longest line, in axes coordinates.
-
integration_direction((both, forward, backward), default:"both") –Integrate along the field, against it, or both.
-
broken_streamlines(bool, default:True) –Stop a line when it comes too close to another.
-
gridded(bool, default:None) –Whether the rows are a regular grid (see
geom_streamline). -
grid_density(float, default:1) –Scattered rows only:
int(50 * grid_density)grid points per axis. -
smooth(float, default:0.5) –Scattered rows only: Gaussian kernel width in grid steps.
-
n_neighbors(int, default:None) –Scattered rows only: rows per grid point (default
int(n_rows / 50)). -
min_mass(float, default:1) –Scattered rows only: kernel weight threshold,
10 ** (min_mass - 6). -
cutoff_percentile(float, default:5) –Scattered rows only: speed percentile below which grid points are empty.
-
na_rm(bool, default:None) –True removes rows with missing values silently.
-
**other_args(Any) –Constant aesthetics and the geom's options (
arrow=arrow()).
Returns:
-
LayerSpec–The layer.
Raises:
-
SpecError–If
integration_directionis unknown, or a density,smoothorn_neighborsis not positive. -
UnsupportedValueError–If an option has the wrong type.
Examples:
>>> from ggrust import *
>>> import numpy as np
>>> east, north = np.meshgrid(np.linspace(-2, 2, 21), np.linspace(-2, 2, 21))
>>> field = {"x": east.ravel(), "y": north.ravel(), "u": -north.ravel(), "v": east.ravel()}
>>> plot = ggplot(field, aes("x", "y", u="u", v="v")) + stat_streamline(
... geom="path", arrow=arrow(length=5)
... )