def velocity(adata, var_names=None, basis=None, groupby=None, groups=None, mode=None, fits='<STR_LIT:all>', layers='<STR_LIT:all>',<EOL>color=None, color_map='<STR_LIT>', colorbar=False, perc=[<NUM_LIT:2>,<NUM_LIT>], use_raw=False, size=None, alpha=<NUM_LIT>,<EOL>fontsize=None, figsize=None, dpi=None, show=True, save=None, ax=None, ncols=None, **kwargs):
basis = default_basis(adata) if basis is None else basis<EOL>if isinstance(groupby, str) and groupby in adata.obs.keys():<EOL><INDENT>if '<STR_LIT>' not in adata.uns.keys() or adata.uns['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] != groupby:<EOL><INDENT>rank_velocity_genes(adata, vkey='<STR_LIT>', n_genes=<NUM_LIT:10>, groupby=groupby)<EOL><DEDENT>names = np.array(adata.uns['<STR_LIT>']['<STR_LIT>'].tolist())<EOL>if groups is None:<EOL><INDENT>var_names = names[:, <NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>groups = [groups] if isinstance(groups, str) else groups<EOL>idx = np.array([any([g in group for g in groups]) for group in adata.obs[groupby].cat.categories])<EOL>var_names = np.hstack(names[idx, :int(<NUM_LIT:10> / idx.sum())])<EOL><DEDENT><DEDENT>elif var_names is not None:<EOL><INDENT>var_names = [var_names] if isinstance(var_names, str) else [var for var in var_names if var in adata.var_names]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>var_names = pd.unique(var_names)<EOL>(skey, ukey) = ('<STR_LIT>', '<STR_LIT>') if use_raw else ('<STR_LIT>', '<STR_LIT>')<EOL>layers = ['<STR_LIT>', skey, '<STR_LIT>'] if layers == '<STR_LIT:all>' else layers<EOL>layers = [layer for layer in layers if layer in adata.layers.keys()]<EOL>fits = adata.layers.keys() if fits == '<STR_LIT:all>' else fits<EOL>fits = [fit for fit in fits if all(['<STR_LIT>' in fit, fit + '<STR_LIT>' in adata.var.keys()])]<EOL>stochastic_fits = [fit for fit in fits if '<STR_LIT>' + fit in adata.layers.keys()]<EOL>nplts = (<NUM_LIT:1> + len(layers) + (mode == '<STR_LIT>') * <NUM_LIT:2>)<EOL>ncols = <NUM_LIT:1> if ncols is None else ncols<EOL>nrows = int(np.ceil(len(var_names) / ncols))<EOL>ncols = int(ncols * nplts)<EOL>figsize = rcParams['<STR_LIT>'] if figsize is None else figsize<EOL>ax = pl.figure(figsize=(figsize[<NUM_LIT:0>] * ncols / <NUM_LIT:2>, figsize[<NUM_LIT:1>] * nrows / <NUM_LIT:2>), dpi=dpi) if ax is None else ax<EOL>gs = pl.GridSpec(nrows, ncols, wspace=<NUM_LIT>, hspace=<NUM_LIT:0.5>)<EOL>size = default_size(adata) / <NUM_LIT:2> if size is None else size  <EOL>fontsize = rcParams['<STR_LIT>'] if fontsize is None else fontsize<EOL>for v, var in enumerate(var_names):<EOL><INDENT>_adata = adata[:, var]<EOL>s, u = _adata.layers[skey], _adata.layers[ukey]<EOL>if issparse(s): s, u = s.A, u.A<EOL>ax = pl.subplot(gs[v * nplts])<EOL>scatter(adata, basis=var, color=color, colorbar=colorbar, frameon=True, title=var, size=size, use_raw=use_raw,<EOL>alpha=alpha, fontsize=fontsize, xlabel='<STR_LIT>', ylabel='<STR_LIT>', show=False, ax=ax, save=False,<EOL>legend_loc=None if v < len(var_names)-<NUM_LIT:1> else '<STR_LIT>', **kwargs)<EOL>for l, layer in enumerate(layers):<EOL><INDENT>ax = pl.subplot(gs[v * nplts + l + <NUM_LIT:1>])<EOL>title = '<STR_LIT>' if layer == skey else layer<EOL>scatter(adata, basis=basis, color=var, layer=layer, color_map=color_map, colorbar=colorbar, title=title,<EOL>perc=perc, use_raw=use_raw, fontsize=fontsize, size=size, alpha=alpha, frameon=False, show=False, ax=ax, save=False, **kwargs)<EOL><DEDENT>if mode == '<STR_LIT>':<EOL><INDENT>ss, us = second_order_moments(_adata)<EOL>ss, us = ss.flatten(), us.flatten()<EOL>fit = stochastic_fits[<NUM_LIT:0>]<EOL>ax = pl.subplot(gs[v * nplts + len(layers) + <NUM_LIT:1>])<EOL>offset = _adata.var[fit + '<STR_LIT>'] if fit + '<STR_LIT>' in adata.var.keys() else <NUM_LIT:0><EOL>beta = _adata.var[fit + '<STR_LIT>'] if fit + '<STR_LIT>' in adata.var.keys() else <NUM_LIT:1><EOL>x = <NUM_LIT:2> * (ss - s**<NUM_LIT:2>) - s<EOL>y = <NUM_LIT:2> * (us - u * s) + u + <NUM_LIT:2> * s * offset / beta<EOL>scatter(adata, x=x, y=y, color=color, colorbar=colorbar, title=var, fontsize=<NUM_LIT>/ncols, size=size, perc=perc,<EOL>xlabel=r'<STR_LIT>', ylabel=r'<STR_LIT>',<EOL>use_raw=use_raw, frameon=True, ax=ax, save=False, show=False, **kwargs)<EOL>xnew = np.linspace(x.min(), x.max() * <NUM_LIT>)<EOL>for fit in stochastic_fits:<EOL><INDENT>gamma = _adata.var[fit + '<STR_LIT>'].values if fit + '<STR_LIT>' in adata.var.keys() else <NUM_LIT:1><EOL>beta = _adata.var[fit + '<STR_LIT>'].values if fit + '<STR_LIT>' in adata.var.keys() else <NUM_LIT:1><EOL>offset2 = _adata.var[fit + '<STR_LIT>'].values if fit + '<STR_LIT>' in adata.var.keys() else <NUM_LIT:0><EOL>pl.plot(xnew, gamma / beta * xnew + offset2 / beta, c='<STR_LIT:k>', linestyle='<STR_LIT>')<EOL><DEDENT>if v == len(var_names) - <NUM_LIT:1>: pl.legend(fits, loc='<STR_LIT>', prop={'<STR_LIT:size>': <NUM_LIT>/ncols})<EOL><DEDENT><DEDENT>savefig_or_show('<STR_LIT>', dpi=dpi, save=save, show=show)<EOL>if not show: return ax<EOL>
Phase and velocity plot for set of genes.

    The phase plot shows spliced against unspliced expressions with steady-state fit.
    Further the embedding is shown colored by velocity and expression.

    Arguments
    ---------
    adata: :class:`~anndata.AnnData`
        Annotated data matrix.
    var_names: `str` or list of `str` (default: `None`)
        Which variables to show.
    basis: `str` (default: `'umap'`)
        Key for embedding coordinates.
    mode: `'stochastic'` or `None` (default: `None`)
        Whether to show show covariability phase portrait.
    fits: `str` or list of `str` (default: `'all'`)
        Which steady-state estimates to show.
    layers: `str` or list of `str` (default: `'all'`)
        Which layers to show.
    color: `str`,  list of `str` or `None` (default: `None`)
        Key for annotations of observations/cells or variables/genes
    color_map: `str` (default: `matplotlib.rcParams['image.cmap']`)
        String denoting matplotlib color map.
    perc: tuple, e.g. [2,98] (default: `None`)
        Specify percentile for continuous coloring.
    size: `float` (default: 5)
        Point size.
    alpha: `float` (default: 1)
        Set blending - 0 transparent to 1 opaque.
    fontsize: `float` (default: `None`)
        Label font size.
    figsize: tuple (default: `(7,5)`)
        Figure size.
    dpi: `int` (default: 80)
        Figure dpi.
    show: `bool`, optional (default: `None`)
        Show the plot, do not return axis.
    save: `bool` or `str`, optional (default: `None`)
        If `True` or a `str`, save the figure. A string is appended to the default filename.
        Infer the filetype if ending on {'.pdf', '.png', '.svg'}.
    ax: `matplotlib.Axes`, optional (default: `None`)
        A matplotlib axes object. Only works if plotting a single component.