pegasus.scatter¶
- pegasus.scatter(data, attrs=None, basis='umap', matkey=None, restrictions=None, show_background=False, fix_corners=True, alpha=1.0, legend_loc='right margin', 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, return_fig=False, dpi=300.0, **kwargs)[source]¶
Generate scatter plots for different attributes
- Parameters
data (
pegasusio.MultimodalData
) – Use current selected modality in data.attrs (
str
orList[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
, optional, default:umap
) – Basis to be used to generate scatter plots. Can be either ‘umap’, ‘tsne’, ‘fitsne’, ‘fle’, ‘net_tsne’, ‘net_fitsne’, ‘net_umap’ or ‘net_fle’.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
orList[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 inattrs
and takes the format of ‘key:value,value…’, or ‘key:~value,value…’. This restriction selects cells with thedata.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
orList[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
orList[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_ncol (
str
, optional, default: None) – Only applicable if legend_loc == “right margin”. Set number of columns used to show legends.palettes (
str
orList[str]
, optional, default: None) – Used for setting colors for every categories in categorical attributes. Each string inpalettes
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
orList[str]
, optional, default:YlOrRd
) – Used for setting colormap for numeric attributes. Each string incmaps
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 (defualt: 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]).
return_fig (
bool
, optional, default:False
) – Return aFigure
object ifTrue
; returnNone
otherwise.dpi (
float
, optional, default: 300.0) – The resolution of the figure in dots-per-inch.
- Returns
A
matplotlib.figure.Figure
object containing the dot plot ifreturn_fig == True
- Return type
Figure object
Examples
>>> pg.scatter(data, attrs=['louvain_labels', 'Channel'], basis='fitsne') >>> pg.scatter(data, attrs=['CD14', 'TRAC'], basis='umap')