def heatmap(adata, var_names, groups=None, groupby=None, annotations=None, use_raw=False, layers=['<STR_LIT:X>'], color_map=None,<EOL>color_map_anno=None, colorbar=True, row_width=None, xlabel=None, title=None, figsize=None, dpi=None,<EOL>show=True, save=None, ax=None, **kwargs):
<EOL>if '<STR_LIT>' not in adata.obs.keys():<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if annotations is None:<EOL><INDENT>annotations = []<EOL><DEDENT>if isinstance(var_names, str):<EOL><INDENT>var_names = [var_names]<EOL><DEDENT>if len(var_names) == <NUM_LIT:0>:<EOL><INDENT>var_names = np.arange(adata.X.shape[<NUM_LIT:1>])<EOL><DEDENT>if var_names.ndim == <NUM_LIT:2>:<EOL><INDENT>var_names = var_names[:, <NUM_LIT:0>]<EOL><DEDENT>var_names = [name for name in var_names if name in adata.var_names]<EOL>if len(var_names) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if layers is None:<EOL><INDENT>layers = ['<STR_LIT:X>']<EOL><DEDENT>if isinstance(layers, str):<EOL><INDENT>layers = [layers]<EOL><DEDENT>layers = [layer for layer in layers if layer in adata.layers.keys() or layer == '<STR_LIT:X>']<EOL>if len(layers) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if not use_raw:<EOL><INDENT>layers = np.array(layers)<EOL>if '<STR_LIT:X>' in layers: layers[np.array([layer == '<STR_LIT:X>' for layer in layers])] = '<STR_LIT>'<EOL>if '<STR_LIT>' in layers: layers[np.array([layer == '<STR_LIT>' for layer in layers])] = '<STR_LIT>'<EOL>if '<STR_LIT>' in layers: layers[np.array([layer == '<STR_LIT>' for layer in layers])] = '<STR_LIT>'<EOL>layers = list(layers)<EOL><DEDENT>if '<STR_LIT>' in layers and '<STR_LIT>' not in adata.layers.keys():<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if '<STR_LIT>' in layers and '<STR_LIT>' not in adata.layers.keys():<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>layers = unique(layers)<EOL>tot_len = len(var_names) * len(layers) + len(annotations)<EOL>figsize = rcParams['<STR_LIT>'] if figsize is None else figsize<EOL>if row_width is not None: figsize[<NUM_LIT:1>] = row_width * tot_len<EOL>ax = pl.figure(figsize=figsize, dpi=dpi).gca() if ax is None else ax<EOL>ax.set_yticks([])<EOL>ax.set_xticks([])<EOL>ax_bounds = ax.get_position().bounds<EOL>if groupby is not None:<EOL><INDENT>if groupby not in adata.obs_keys():<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if groups is None:  <EOL><INDENT>groups = unique(adata.obs.clusters.values)<EOL><DEDENT>imlist = []<EOL>for igroup, group in enumerate(groups):<EOL><INDENT>for ivar, var in enumerate(var_names):<EOL><INDENT>for ilayer, layer in enumerate(layers):<EOL><INDENT>groups_axis = pl.axes([ax_bounds[<NUM_LIT:0>] + igroup * ax_bounds[<NUM_LIT:2>] / len(groups),<EOL>ax_bounds[<NUM_LIT:1>] + ax_bounds[<NUM_LIT:3>] * (<EOL>tot_len - ivar * len(layers) - ilayer - <NUM_LIT:1>) / tot_len,<EOL>ax_bounds[<NUM_LIT:2>] / len(groups),<EOL>(ax_bounds[<NUM_LIT:3>] - ax_bounds[<NUM_LIT:3>] / tot_len * len(annotations)) / (<EOL>len(var_names) * len(layers))])<EOL>dat = adata[:, var]<EOL>idx_group = [adata.obs[groupby] == group]<EOL>idx_group = np.array(idx_group[<NUM_LIT:0>].tolist())<EOL>idx_var = [vn in var_names for vn in adata.var_names]<EOL>idx_pt = np.array(adata.obs.velocity_pseudotime).argsort()<EOL>idx_pt = idx_pt[np.array(np.isnan(np.array(dat.obs.velocity_pseudotime)[idx_pt]) == False)]<EOL>if layer == '<STR_LIT:X>':<EOL><INDENT>laydat = dat.X<EOL><DEDENT>else:<EOL><INDENT>laydat = dat.layers[layer]<EOL><DEDENT>t1, t2, t3 = idx_group, idx_var, idx_pt<EOL>t1 = t1[t3]<EOL>laydat = laydat[t3]<EOL>laydat = laydat[t1]  <EOL>if issparse(laydat):<EOL><INDENT>laydat = laydat.A<EOL><DEDENT>laydat = laydat.T[::-<NUM_LIT:1>]<EOL>laydat = laydat.reshape((<NUM_LIT:1>, len(laydat)))  <EOL>im = groups_axis.imshow(laydat, aspect='<STR_LIT>', interpolation="<STR_LIT>", cmap=color_map[ilayer])<EOL>if ilayer == <NUM_LIT:0>:<EOL><INDENT>groups_axis.spines['<STR_LIT>'].set_visible(False)<EOL><DEDENT>elif ilayer == len(layer) - <NUM_LIT:1>:<EOL><INDENT>groups_axis.spines['<STR_LIT>'].set_visible(False)<EOL><DEDENT>else:<EOL><INDENT>groups_axis.spines['<STR_LIT>'].set_visible(False)<EOL>groups_axis.spines['<STR_LIT>'].set_visible(False)<EOL><DEDENT>if igroup == <NUM_LIT:0>:<EOL><INDENT>if colorbar:<EOL><INDENT>if len(layers) % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>if ilayer == len(layers) / <NUM_LIT:2> - <NUM_LIT:1>:<EOL><INDENT>pl.yticks([<NUM_LIT:0.5>], [var])<EOL><DEDENT>else:<EOL><INDENT>groups_axis.set_yticks([])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if ilayer == (len(layers) - <NUM_LIT:1>) / <NUM_LIT:2>:<EOL><INDENT>pl.yticks([<NUM_LIT:0>], [var])<EOL><DEDENT>else:<EOL><INDENT>groups_axis.set_yticks([])<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>pl.yticks([<NUM_LIT:0>], [layer + '<STR_LIT:U+0020>' + var])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>groups_axis.set_yticks([])<EOL><DEDENT>groups_axis.set_xticks([])<EOL>if ilayer == <NUM_LIT:0> and ivar == <NUM_LIT:0>:<EOL><INDENT>groups_axis.set_title(str(group))<EOL><DEDENT>groups_axis.grid(False)<EOL>if igroup == len(groups) - <NUM_LIT:1>:<EOL><INDENT>imlist.append(im)<EOL><DEDENT><DEDENT><DEDENT>if annotations is not None:<EOL><INDENT>for ianno, anno in enumerate(annotations):<EOL><INDENT>anno_axis = pl.axes([ax_bounds[<NUM_LIT:0>] + igroup * ax_bounds[<NUM_LIT:2>] / len(groups),<EOL>ax_bounds[<NUM_LIT:1>] + ax_bounds[<NUM_LIT:3>] / tot_len * (len(annotations) - ianno - <NUM_LIT:1>),<EOL>ax_bounds[<NUM_LIT:2>] / len(groups),<EOL>ax_bounds[<NUM_LIT:3>] / tot_len])<EOL>if is_categorical(adata, anno):<EOL><INDENT>colo = interpret_colorkey(adata, anno)[t3][t1]<EOL>colo.reshape(<NUM_LIT:1>, len(colo))<EOL>mapper = np.vectorize(ColorConverter.to_rgb)<EOL>a = mapper(colo)<EOL>a = np.array(a).T<EOL>Y = a.reshape(<NUM_LIT:1>, len(colo), <NUM_LIT:3>)<EOL><DEDENT>else:<EOL><INDENT>Y = np.array(interpret_colorkey(adata, anno))[t3][t1]<EOL>Y = Y.reshape(<NUM_LIT:1>, len(Y))<EOL><DEDENT>img = anno_axis.imshow(Y, aspect='<STR_LIT>',<EOL>interpolation='<STR_LIT>', cmap=color_map_anno)<EOL>if igroup == <NUM_LIT:0>:<EOL><INDENT>anno_axis.set_yticklabels(['<STR_LIT>', anno, '<STR_LIT>'])  <EOL>anno_axis.tick_params(axis='<STR_LIT>', which='<STR_LIT>', length=<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>anno_axis.set_yticklabels([])<EOL>anno_axis.set_yticks([])<EOL><DEDENT>anno_axis.set_xticks([])<EOL>anno_axis.set_xticklabels([])<EOL>anno_axis.grid(False)<EOL>pl.ylim([<NUM_LIT>, -<NUM_LIT>])  <EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:  <EOL><INDENT>imlist = []<EOL>for ivar, var in enumerate(var_names):<EOL><INDENT>for ilayer, layer in enumerate(layers):<EOL><INDENT>ax_bounds = ax.get_position().bounds<EOL>groups_axis = pl.axes([ax_bounds[<NUM_LIT:0>],<EOL>ax_bounds[<NUM_LIT:1>] + ax_bounds[<NUM_LIT:3>] * (<EOL>tot_len - ivar * len(layers) - ilayer - <NUM_LIT:1>) / tot_len,<EOL>ax_bounds[<NUM_LIT:2>],<EOL>(ax_bounds[<NUM_LIT:3>] - ax_bounds[<NUM_LIT:3>] / tot_len * len(annotations)) / (<EOL>len(var_names) * len(layers))])<EOL>dat = adata[:, var]<EOL>idx = np.array(dat.obs.velocity_pseudotime).argsort()<EOL>idx = idx[np.array(np.isnan(np.array(dat.obs.velocity_pseudotime)[idx]) == False)]<EOL>if layer == '<STR_LIT:X>':<EOL><INDENT>laydat = dat.X<EOL><DEDENT>else:<EOL><INDENT>laydat = dat.layers[layer]<EOL><DEDENT>laydat = laydat[idx]<EOL>if issparse(laydat):<EOL><INDENT>laydat = laydat.A<EOL><DEDENT>laydat = laydat.T[::-<NUM_LIT:1>]<EOL>laydat = laydat.reshape((<NUM_LIT:1>, len(laydat)))<EOL>im = groups_axis.imshow(laydat, aspect='<STR_LIT>', interpolation="<STR_LIT>", cmap=color_map[ilayer])<EOL>imlist.append(im)<EOL>if ilayer == <NUM_LIT:0>:<EOL><INDENT>groups_axis.spines['<STR_LIT>'].set_visible(False)<EOL><DEDENT>elif ilayer == len(layer) - <NUM_LIT:1>:<EOL><INDENT>groups_axis.spines['<STR_LIT>'].set_visible(False)<EOL><DEDENT>else:<EOL><INDENT>groups_axis.spines['<STR_LIT>'].set_visible(False)<EOL>groups_axis.spines['<STR_LIT>'].set_visible(False)<EOL><DEDENT>groups_axis.set_xticks([])<EOL>groups_axis.grid(False)<EOL>pl.ylim([<NUM_LIT>, -<NUM_LIT>])  <EOL>if colorbar:<EOL><INDENT>if len(layers) % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>if ilayer == len(layers) / <NUM_LIT:2> - <NUM_LIT:1>:<EOL><INDENT>pl.yticks([<NUM_LIT:0.5>], [var])<EOL><DEDENT>else:<EOL><INDENT>groups_axis.set_yticks([])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if ilayer == (len(layers) - <NUM_LIT:1>) / <NUM_LIT:2>:<EOL><INDENT>pl.yticks([<NUM_LIT:0>], [var])<EOL><DEDENT>else:<EOL><INDENT>groups_axis.set_yticks([])<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>pl.yticks([<NUM_LIT:0>], [layer + '<STR_LIT:U+0020>' + var])<EOL><DEDENT><DEDENT><DEDENT>if annotations is not None:<EOL><INDENT>for ianno, anno in enumerate(annotations):<EOL><INDENT>anno_axis = pl.axes([ax_bounds[<NUM_LIT:0>],<EOL>ax_bounds[<NUM_LIT:1>] + ax_bounds[<NUM_LIT:3>] / tot_len * (len(annotations) - ianno - <NUM_LIT:1>),<EOL>ax_bounds[<NUM_LIT:2>],<EOL>ax_bounds[<NUM_LIT:3>] / tot_len])<EOL>dat = adata[:, var_names]<EOL>if is_categorical(dat, anno):<EOL><INDENT>colo = interpret_colorkey(dat, anno)[idx]<EOL>colo.reshape(<NUM_LIT:1>, len(colo))<EOL>mapper = np.vectorize(ColorConverter.to_rgb)<EOL>a = mapper(colo)<EOL>a = np.array(a).T<EOL>Y = a.reshape(<NUM_LIT:1>, len(idx), <NUM_LIT:3>)<EOL><DEDENT>else:<EOL><INDENT>Y = np.array(interpret_colorkey(dat, anno)[idx]).reshape(<NUM_LIT:1>, len(idx))<EOL><DEDENT>img = anno_axis.imshow(Y, aspect='<STR_LIT>', interpolation='<STR_LIT>', cmap=color_map_anno)<EOL>anno_axis.set_yticklabels(['<STR_LIT>', anno, '<STR_LIT>'])  <EOL>anno_axis.tick_params(axis='<STR_LIT>', which='<STR_LIT>', length=<NUM_LIT:0>)<EOL>anno_axis.grid(False)<EOL>anno_axis.set_xticks([])<EOL>anno_axis.set_xticklabels([])<EOL>pl.ylim([-<NUM_LIT>, +<NUM_LIT>])<EOL><DEDENT><DEDENT><DEDENT>if colorbar:<EOL><INDENT>if len(layers) > <NUM_LIT:1>:<EOL><INDENT>for ilayer, layer in enumerate(layers):<EOL><INDENT>w = <NUM_LIT> * <NUM_LIT:10> / figsize[<NUM_LIT:0>]  <EOL>x = ax_bounds[<NUM_LIT:0>] + ax_bounds[<NUM_LIT:2>] * <NUM_LIT> + <NUM_LIT> * w + w * <NUM_LIT> * ilayer<EOL>y = ax_bounds[<NUM_LIT:1>]<EOL>h = ax_bounds[<NUM_LIT:3>] * <NUM_LIT><EOL>cbaxes = pl.axes([x, y, w, h])<EOL>cb = pl.colorbar(mappable=imlist[ilayer], cax=cbaxes)<EOL>pl.text(x - <NUM_LIT> * w, y + h * <NUM_LIT:4>, layer, rotation=<NUM_LIT>, horizontalalignment='<STR_LIT:left>',<EOL>verticalalignment='<STR_LIT>')<EOL>if ilayer == len(layers) - <NUM_LIT:1>:<EOL><INDENT>ext = abs(cb.vmin - cb.vmax)<EOL>cb.set_ticks([cb.vmin + <NUM_LIT> * ext, cb.vmax - <NUM_LIT> * ext])<EOL>cb.ax.set_yticklabels(['<STR_LIT>', '<STR_LIT>'])  <EOL><DEDENT>else:<EOL><INDENT>cb.set_ticks([])<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>cbaxes = pl.axes([ax_bounds[<NUM_LIT:0>] + ax_bounds[<NUM_LIT:2>] + <NUM_LIT>,<EOL>ax_bounds[<NUM_LIT:1>],<EOL><NUM_LIT>,<EOL>ax_bounds[<NUM_LIT:3>] * <NUM_LIT>])<EOL>cb = pl.colorbar(mappable=im, cax=cbaxes)<EOL>cb.set_ticks([cb.vmin, cb.vmax])<EOL>cb.ax.set_yticklabels(['<STR_LIT>', '<STR_LIT>'])<EOL><DEDENT><DEDENT>if xlabel is None: xlabel = '<STR_LIT>' + '<STR_LIT:U+0020>' + '<STR_LIT>'<EOL>if title is not None: ax.set_title(title, pad=<NUM_LIT:30>)<EOL>if len(annotations) == <NUM_LIT:0>:<EOL><INDENT>ax.set_xlabel(xlabel)<EOL>ax.xaxis.labelpad = <NUM_LIT:20><EOL><DEDENT>savefig_or_show('<STR_LIT>', dpi=dpi, save=save, show=show)<EOL>if not show: return ax<EOL>
\
    Plot pseudotimeseries for genes as heatmap.

    Arguments
    ---------
    adata: :class:`~anndata.AnnData`
        Annotated data matrix.
    var_names: `str`,  list of `str`
        Names of variables to use for the plot.
    groups: `str`,  list of `str` or `None` (default: `None`)
        Groups selected to plot. Must be an element of adata.obs[groupby].
    groupby: `str` or `None` (default: `None`)
        Key in adata.obs. Indicates how to group the plot.
    annotations: `str`,  list of `str` or `None` (default: `None`)
        Key in adata.obs. Annotations are plotted in the last row.
    use_raw: `bool` (default: `False`)
        If true, moments are used instead of raw data.
    layers: `str`,  list of `str` or `None` (default: `['X']`)
        Selected layers.
    color_map: `str`,  list of `str` or `None` (default: `None`)
        String denoting matplotlib color map for the heat map.
        There must be one list entry for each layer.
    color_map_anno: `str`,  list of `str` or `None` (default: `None`)
        String denoting matplotlib color map for the annotations.
        There must be one list entry for each annotation.
    colorbar: `bool` (default: `True`)
        If True, a colormap for each layer is added on the right bottom corner.
    row_width: `float` (default: `None`)
        Constant width of all rows.
    xlabel:
        Label for the x-axis.
    title: `str` or `None` (default: `None`)
        Main plot title.
    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.

    Returns
    -------
        If `show==False` a `matplotlib.Axis`