scanpy.pl.scatter

scanpy.pl.scatter(adata, x=None, y=None, color=None, use_raw=None, layers=None, sort_order=True, alpha=None, basis=None, groups=None, components=None, projection='2d', legend_loc='right margin', legend_fontsize=None, legend_fontweight=None, legend_fontoutline=None, color_map=None, palette=None, frameon=None, right_margin=None, left_margin=None, size=None, title=None, show=None, save=None, ax=None)

Scatter plot along observations or variables axes.

Color the plot using annotations of observations (.obs), variables (.var) or expression of genes (.var_names).

Parameters
adata : AnnData

Annotated data matrix.

x : str or None

x coordinate.

y : str or None

y coordinate.

color : string or list of strings, optional (default: None)

Keys for annotations of observations/cells or variables/genes, or a hex color specification, e.g., 'ann1', '#fe57a1', or ['ann1', 'ann2'].

use_raw : bool, optional (default: None)

Use raw attribute of adata if present.

layers : str or tuple of strings, optional (default: X)

Use the layers attribute of adata if present: specify the layer for x, y and color. If layers is a string, then it is expanded to (layers, layers, layers).

basis : {'pca', 'tsne', 'umap', 'diffmap', 'draw_graph_fr', etc.}

String that denotes a plotting tool that computed coordinates.

sort_order

For continuous annotations used as color parameter, plot data points with higher values on top of others.

groups

Restrict to a few categories in categorical observation annotation. The default is not to restrict to any groups.

components

For instance, ['1,2', '2,3']. To plot all available components use components='all'.

projection : {'2d', '3d'}, optional (default: '2d')

Projection of plot.

legend_loc

Location of legend, either ‘on data’, ‘right margin’ or valid keywords for matplotlib.legend.

legend_fontsize

Legend font size.

legend_fontweight : {‘normal’, ‘bold’, …}, optional (default: None)

Legend font weight. Defaults to ‘bold’ if legend_loc == 'on data', otherwise to ‘normal’. Available are ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black'].

legend_fontoutline

Linewidth of the legend font outline. This uses matplotlib.patheffects to draw a white outline around the legend text.

size

Point size. If None, is automatically computed.

color_map

Color map to use for continous variables. Anything that works for cmap argument of pyplot.scatter should work here (e.g. "magma", "viridis", mpl.cm.cividis). If None value of mpl.rcParams["image.cmap"] is used.

palette

Colors to use for plotting categorical annotation groups. The palette can be a valid matplotlib.pyplot.colormap name like 'Set2' or 'tab20', a list of colors like ['red', '#ccdd11', (0.1, 0.2, 1)] or a Cycler object. If None, mpl.rcParams["axes.prop_cycle"] is used unless the categorical variable already has colors stored in adata.uns["{var}_colors"]. If provided, values of adata.uns["{var}_colors"] will be set by this palette.

frameon

Draw a frame around the scatter plot. Defaults to value set in set_figure_params(), defaults to True.

title

Provide title for panels either as string or list of strings, e.g. ['title1', 'title2', ...].

kwargs : further keyword arguments, optional

Arguments to pass to matplotlib.pyplot.scatter(), for instance: the maximum and minimum values (e.g. vmin=-2, vmax=5).

return_fig

Return the matplotlib figure.

show

Show the plot, do not return axis.

save

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

A matplotlib axes object. Only works if plotting a single component.

Returns

If show==False a Axes or a list of it.