pegasus.scatter_groups¶
- pegasus.scatter_groups(data, attr, groupby, basis='umap', matkey=None, restrictions=None, show_full=True, categories=None, alpha=1.0, legend_loc='right margin', legend_ncol=None, palette=None, cmap='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, show_neg_for_sig=False, **kwargs)[source]¶
Generate scatter plots of attribute ‘attr’ for each category in attribute ‘group’. Optionally show scatter plot containing data points from all categories in ‘group’.
- Parameters
data (
pegasusio.MultimodalData
) – Use current selected modality in data.attr (
str
) – Color scatter plots by attribute ‘attr’. This attribute should 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 it is categorical, a palette will be used to color each category separately. Otherwise, a color map will be used.groupby (
str
) – Generate separate scatter plots of ‘attr’ for data points in each category in ‘groupby’, which should be a key in data.obs representing one categorical variable.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. Each restriction 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).show_full (
bool
, optional, default: True) – Show the scatter plot with all categories in ‘groupby’ as the first plot.categories (
List[str]
, optional, default: None) – Redefine group structure based on attribute ‘groupby’. If ‘categories’ is not None, each string in the list takes the format of ‘category_name:value,value’, or ‘category_name:~value,value…”, where ‘category_name’ refers to new category name, ‘value’ refers to one of the category in ‘groupby’ and ‘~’ refers to exclude values.alpha (
float
, optional, default:1.0
) – Alpha value for blending, from 0.0 (transparent) to 1.0 (opaque).legend_loc (
str
, optional, default:right margin
) – Legend location. Can be either “right margin” or “on data”.legend_ncol (
str
, optional, default: None) – Only applicable if legend_loc == “right margin”. Set number of columns used to show legends.palette (
str
, optional, default: None) – Used for setting colors for one categorical attribute (e.g. “black,blue,red,…,yellow”).cmap (
str
, optional, default:YlOrRd
) – Used for setting colormap for one numeric attribute.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.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).
- Returns
A
matplotlib.figure.Figure
object containing the dot plot ifreturn_fig == True
- Return type
Figure object
Examples
>>> pg.scatter_groups(data, attr='louvain_labels', groupby='Individual', basis='tsne', nrows = 2, ncols = 4, alpha = 0.5) >>> pg.scatter_groups(data, attr='anno', groupby='Channel', basis='umap', categories=['new_cat1:channel1,channel2', 'new_cat2:channel3'])