stream#
- stream(*, plot: PlotSpec | None = None, color: str = '#1f1f1f', alpha: float = 0.7, size: float = 1, velocity_prefix: str = 'velocity_', velocity_key: str | None = None, grid_density: float = 1, smooth: float = 0.5, n_neighbors: int | None = None, min_mass: int = 1, cutoff_percentile: None = None, density: float = 2, max_length: float = 4, integration_direction: Literal['forward', 'backward', 'both'] = 'both', mapping: FeatureSpec | None = None, arrow_color: str = '#1f1f1f', arrow_size: float = 1, arrow_alpha: float = 0.7, arrows: FeatureSpec | None = None, arrow_kwargs: dict | None = None, **geom_kwargs) DeferredLayer#
Layer of streams of velocities on the embedding.
- Parameters:
plot (
PlotSpec | None, defaultNone) – If provided, streams are computed from this plot’s data and aesthetics regardless of which plot the resulting layer is added to. WhenNone, the layer is deferred and introspects the plot it is added to via+.color (
str, default"#1f1f1f") – Color of the stream lines.alpha (
float, default0.7) – Alpha of the stream lines.size (
float, default1) – Size of the stream lines.velocity_prefix (
str, default"velocity_") – Prefix for the velocity columns in the data. The function will look for columns with this prefix followed by the embedding number. (e.g. “velocity_UMAP1”, “velocity_UMAP2”).velocity_key (
str | None, defaultNone) – If provided, will be used as the column names for the velocity. E.g f”{velocity_key}1”, f”{velocity_key}2”. If None, defaults to using velocity_prefix + embedding name.grid_density (
float, default1) – Density of the grid for velocity embedding.smooth (
float, default0.5) – Multiplication factor for scale in Gaussian kernel around grid point.n_neighbors (
int | None, defaultNone) – Number of neighbors to consider around grid point.min_mass (
int, default1) – Minimum threshold for mass to be shown. It can range between 0 (all velocities) and 5 (large velocities only).cutoff_percentile (
float | None, defaultNone) – If set, mask small velocities below a percentile threshold (between 0 and 100).density (
float, default2) – Controls the closeness of streamlines. When density = 2 (default), the domain is divided into a 60x60 grid, whereas density linearly scales this grid. Each cell in the grid can have, at most, one traversing streamline. For different densities in each direction, use a tuple (density_x, density_y).max_length (
float, default4) – Maximum length of streamline in axes coordinates.integration_direction (
{'forward', 'backward', 'both'}, default'both') – Integrate the streamline in ‘forward’, ‘backward’ or ‘both’ directions.mapping (
FeatureSpec | None, defaultNone) – Additional aesthetic mappings for the plot, the result of aes().arrow_color (
str | None, default'#1f1f1f') – Color of the arrows. If None, defaults to the same color as the stream lines.arrow_size (
float, default1) – Size of the arrows.arrow_alpha (
float, default0.7) – Alpha of the arrows.arrows (
FeatureSpec | None, defaultNone) – The result of arrow(), used to specify arrow aesthetics. If None, defaults to arrow(). For more information on arrow parameters, see: https://lets-plot.org/python/pages/api/lets_plot.arrow.htmlarrow_kwargs (
dict | None, defaultNone) – Additional keyword arguments for the arrows to be passed to geom_segment. E.g {“linestyle”: “dashed”}. For more information on arrow parameters, see: https://lets-plot.org/python/pages/api/lets_plot.geom_segment.html**geom_kwargs – Additional parameters for the geom_path layer. For more information on geom_path parameters, see: https://lets-plot.org/python/pages/api/lets_plot.geom_path.html
- Returns:
DeferredLayer
Examples
Stream layers can be added to dimensionality reduction plots.
import scanpy as sc from lets_plot import * import cellestial as cl data = sc.read("data/endocrinogenesis_day15_pped.h5ad") plot = cl.umap( data, key="clusters_coarse", axis_type="arrow", size=4, alpha=0.4, legend_ondata=True, ondata_color="black", ) plot + cl.stream()
Stream as a separate layer to showcase the modularity of layers in Cellestial. Here the data source is passed explicitly because the receiving plot (
ggplot()) has no embedding to introspect.import scanpy as sc from lets_plot import * import cellestial as cl data = sc.read("data/endocrinogenesis_day15_pped.h5ad") plot = cl.umap( data, key="clusters_coarse", axis_type="arrow", size=4, alpha=0.4, legend_ondata=True, ondata_color="black", ) gggrid([plot, ggplot() + cl.stream(plot=plot)])