pegasus.scatter

pegasus.scatter(data, attrs=None, basis='umap', components=(1, 2), matkey=None, restrictions=None, show_background=False, fix_corners=True, alpha=1.0, legend_loc='right margin', legend_fontsize=10, legend_ncol=None, palettes=None, cmaps='YlOrRd', vmin=None, vmax=None, nrows=None, ncols=None, panel_size=(4, 4), left=0.2, bottom=0.15, wspace=0.4, hspace=0.15, marker_size=None, scale_factor=None, return_fig=False, dpi=300.0, show_neg_for_sig=False, **kwargs)[source]

Generate scatter plots for different attributes

Parameters
  • data (pegasusio.MultimodalData) – Use current selected modality in data.

  • attrs (str or List[str], default: None) – Color scatter plots by attrs. Each attribute in attrs can be one key in data.obs, data.var_names (e.g. one gene) or data.obsm (attribute has the format of ‘obsm_key@component’, like ‘X_pca@0’). If one attribute is categorical, a palette will be used to color each category separately. Otherwise, a color map will be used. If no attributes are provided, plot the basis for all data.

  • basis (str or List[str], optional, default: umap) – Basis to be used to generate scatter plots. Can be either ‘pca’, ‘diffmap’, ‘umap’, ‘tsne’, ‘fitsne’, ‘fle’, ‘net_tsne’, ‘net_fitsne’, ‘net_umap’ or ‘net_fle’. If basis is a list, each of element in attrs will be plotted for each basis in basis.

  • components (Tuple[int, int] or List[Tuple[int, int]], optional, default: (1, 2)) – Components in basis to be used. Default to the first two components. If components is a list, for each element in attrs and each basis, all components enumeration will be plotted.

  • matkey (str, optional, default: None) – If matkey is set, select matrix with matkey as keyword in the current modality. Only works for MultimodalData or UnimodalData objects.

  • restrictions (str or List[str], optional, default: None) – A list of restrictions to subset data for plotting. There are two types of restrictions: global restriction and attribute-specific restriction. Global restriction appiles to all attributes in attrs and takes the format of ‘key:value,value…’, or ‘key:~value,value…’. This restriction selects cells with the data.obs[key] values belong to ‘value,value…’ (or not belong to if ‘~’ shows). Attribute-specific restriction takes the format of ‘attr:key:value,value…’, or ‘attr:key:~value,value…’. It only applies to one attribute ‘attr’. If ‘attr’ and ‘key’ are the same, one can use ‘.’ to replace ‘key’ (e.g. cluster_labels:.:value1,value2).

  • show_background (bool, optional, default: False) – Only applicable if restrictions is set. By default, only data points selected are shown. If show_background is True, data points that are not selected will also be shown.

  • fix_corners (bool, optional, default: True) – If True, fix the corners of the plots as defined using all data points.

  • alpha (float or List[float], optional, default: 1.0) – Alpha value for blending, from 0.0 (transparent) to 1.0 (opaque). If this is a list, the length must match attrs, which means we set a separate alpha value for each attribute.

  • legend_loc (str or List[str], optional, default: right margin) – Legend location. Can be either “right margin” or “on data”. If a list is provided, set ‘legend_loc’ for each attribute in ‘attrs’ separately.

  • legend_fontsize (int or List[int], optional, default: 10) – Legend fontsize. If a list is provided, set ‘legend_fontsize’ for each attribute in ‘attrs’ separately.

  • legend_ncol (str, optional, default: None) – Only applicable if legend_loc == “right margin”. Set number of columns used to show legends.

  • palettes (str or List[str], optional, default: None) – Used for setting colors for every categories in categorical attributes. Each string in palettes takes the format of ‘attr:color1,color2,…,colorn’. ‘attr’ is the categorical attribute and ‘color1’ - ‘colorn’ are the colors for each category in ‘attr’ (e.g. ‘cluster_labels:black,blue,red,…,yellow’). If there is only one categorical attribute in ‘attrs’, palletes can be set as a single string and the ‘attr’ keyword can be omitted (e.g. “blue,yellow,red”).

  • cmaps (str or List[str], optional, default: YlOrRd) – Used for setting colormap for numeric attributes. Each string in cmaps takes the format of ‘colormap’ or ‘attr:colormap’. ‘colormap’ sets the default colormap for all numeric attributes. ‘attr:colormap’ overwrites attribute ‘attr’s colormap as ‘colormap’.

  • vmin (float, optional, default: None) – Minimum value to show on a numeric scatter plot (feature plot).

  • vmax (float, optional, default: None) – Maximum value to show on a numeric scatter plot (feature plot).

  • nrows (int, optional, default: None) – Number of rows in the figure. If not set, pegasus will figure it out automatically.

  • ncols (int, optional, default: None) – Number of columns in the figure. If not set, pegasus will figure it out automatically.

  • panel_size (tuple, optional (default: (6, 4))) – The panel size (width, height) in inches.

  • left (float, optional (default: 0.2)) – This parameter sets the figure’s left margin as a fraction of panel’s width (left * panel_size[0]).

  • bottom (float, optional (default: 0.15)) – This parameter sets the figure’s bottom margin as a fraction of panel’s height (bottom * panel_size[1]).

  • wspace (float, optional (default: 0.4)) – This parameter sets the width between panels and also the figure’s right margin as a fraction of panel’s width (wspace * panel_size[0]).

  • hspace (float, optional (default: 0.15)) – This parameter sets the height between panels and also the figure’s top margin as a fraction of panel’s height (hspace * panel_size[1]).

  • marker_size (float, optional (default: None)) – Manually set the marker size in the plot. If None, automatically adjust the marker size to the plot size.

  • scale_factor (float, optional (default: None)) – Manually set the scale factor in the plot if it’s not None. This is used by generating the spatial plots for 10x Visium data.

  • return_fig (bool, optional, default: False) – Return a Figure object if True; return None otherwise.

  • dpi (float, optional, default: 300.0) – The resolution of the figure in dots-per-inch.

  • show_neg_for_sig (bool, optional, default: False) – For signature scores (i.e. attribute type registered as ‘signature’), if we should show negative scores or show them as zeros. Default is False (i.e. show them as zeros).

Return type

Optional[Figure]

Returns

  • Figure object – A matplotlib.figure.Figure object containing the dot plot if return_fig == True

Examples

>>> pg.scatter(data, attrs=['louvain_labels', 'Channel'], basis='fitsne')
>>> pg.scatter(data, attrs=['CD14', 'TRAC'], basis='umap')