flex_dotplot¶
- besca.pl.flex_dotplot(df, X, Y, HUE, SIZE, title, mycolors='Reds', myfontsize=15, xfactor=0.7, yfactor=0.6, figsize=None)[source]¶
Generate a dot plot showing average expression and fraction positive cells
This function generates a plot where X and Y axes are flexible. For each coordinate a circle plot is generated where the size of the circle represents is specifed by SIZE (typically fraction_pos) and the color of the circle is specified by HUE (typically average expression). X and Y axis for stratification is also specified, typically X would be genes and Y cell types. In case of a single gene, Y could be treatments/patients etc.
- Parameters:
df (pandas.DataFrame) – a dataframe containing the data to be plotted
X (str) – df column to be plotted on X axis
Y (str) – df column to be plotted on Y axis
HUE (str) – df column corresponding to dot color (e.g. average expression)
SIZE (str) – df column corresponding to dot size (e.g. fraction positive)
title (str) – plot title
mycolors (str) – color palette e.g. Reds or viridis
myfontsize (int) – fontsize for the legend defaults to 15
xfactor (int) – distance coef for xaxis defaults to 0.7
yfactor (int) – distance coef for yaxis defaults to 0.6
figsize ((width, height) or None | default = None) – optional parameter to define the figure size of the plot that is to be generated
- Returns:
A matplotlib figure element containing the generated plot. To save the figure this plot will need to be passed to a parameter and saved in a second step through the fig.savefig() function call.
- Return type:
Figure
Examples
>>> # import libraries and dataset >>> import besca as bc >>> adata = bc.datasets.simulated_Kotliarov2020_processed() >>> gene = 'Gene_3' >>> df=bc.get_singlegenedf(gene, adata, 'CONDITION','leiden','sampleid') >>> fig = bc.pl.flex_dotplot(df,'CONDITION','leiden','Avg','Fct','study_title')