adataviz.plotting module

adataviz.plotting.categorical_scatter(data, ax=None, coord_base='umap', x=None, y=None, hue=None, palette='auto', color=None, text_anno=None, text_kws=None, luminance=None, text_transform=None, dodge_text=False, dodge_kws=None, show_legend=False, legend_kws=None, s='auto', size=None, sizes=None, size_norm=None, size_portion=0.95, axis_format='tiny', max_points=50000, labelsize=4, linewidth=0.5, zoomxy=1.05, outline=None, outline_pad=3, alpha=0.7, outline_kws=None, scatter_kws=None, rasterized='auto', coding=False, id_marker=True, legend_color_text=True, rectangle_marker=False, marker_fontsize=4, marker_pad=0.1)[source]

This function was copied from ALLCools and made some modifications. Plot categorical scatter plot with versatile options.

Parameters:
  • rasterized – Whether to rasterize the figure.

  • return_fig – Whether to return the figure.

  • size_portion – The portion of the figure to be used for the size norm.

  • data – Dataframe that contains coordinates and categorical variables

  • ax – this function do not generate ax, must provide an ax

  • coord_base – coords name, if provided, will automatically search for x and y

  • x – x coord name

  • y – y coord name

  • hue (str) – categorical col name or series for color hue.

  • palette (str or dict) – palette for color hue.

  • color – specify single color for all the dots

  • text_anno – categorical col name or series for text annotation.

  • text_kws

    kwargs pass to plt.text, see: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.text.html including bbox, to see parameter for bbox, go to: https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.FancyBboxPatch.html#matplotlib.patches.FancyBboxPatch commonly used parameters are:

    text_kws=dict(fontsize=5,fontweight='black',
                            color='black', # color could be a dict, keys are text to be annotated
                            bbox=dict(boxstyle='round',edgecolor=(0.5, 0.5, 0.5, 0.2),fill=False,
                                                    facecolor=(0.8, 0.8, 0.8, 0.2), # facecolor could also be a dict
                                                    alpha=1,linewidth=0.5)
                            )
    

  • text_transform – transform for text annotation.

  • dodge_text – whether to dodge text annotation.

  • dodge_kws – kwargs for dodge text annotation.

  • show_legend – whether to show legend.

  • legend_kws – kwargs for legend.

  • s – single size value of all the dots.

  • size – mappable size of the dots.

  • sizes – mapping size to the sizes value.

  • size_norm – normalize size range for mapping.

  • axis_format – axis format.

  • max_points – maximum number of points to plot.

  • labelsize – label size pass to ax.text

  • linewidth – line width pass to ax.scatter

  • zoomxy – zoom factor for x and y-axis.

  • outline – categorical col name or series for outline.

  • outline_pad – outline padding.

  • outline_kws – kwargs for outline.

  • scatter_kws – kwargs for scatter.

Returns:

  • if return_fig is True, return the figure and axes.

  • else, return None.

adataviz.plotting.continuous_scatter(data, ax=None, coord_base='umap', x=None, y=None, scatter_kws=None, hue=None, hue_norm=None, hue_portion=0.95, color=None, cmap='viridis', colorbar=True, size=None, size_norm=None, size_portion=0.95, sizes=None, sizebar=True, text_anno=None, dodge_text=False, dodge_kws=None, text_kws=None, luminance=0.48, text_transform=None, axis_format='tiny', max_points=50000, s='auto', labelsize=6, ticklabel_size=4, linewidth=0.5, zoomxy=1.05, outline=None, outline_kws=None, outline_pad=2, return_fig=False, rasterized='auto', cbar_kws=None, cbar_width=3)[source]

Plot scatter on given adata.

Parameters:
  • data (_type_) – _description_

  • ax (_type_, optional) – _description_, by default None

  • coord_base (str, optional) – _description_, by default “umap”

  • x (_type_, optional) – _description_, by default None

  • y (_type_, optional) – _description_, by default None

  • scatter_kws (_type_, optional) – _description_, by default None

  • hue (_type_, optional) – _description_, by default None

  • hue_norm (_type_, optional) – _description_, by default None

  • hue_portion (float, optional) – _description_, by default 0.95

  • color (_type_, optional) – _description_, by default None

  • cmap (str, optional) – _description_, by default “viridis”

  • colorbar (bool, optional) – _description_, by default True

  • size (_type_, optional) – _description_, by default None

  • size_norm (_type_, optional) – _description_, by default None

  • size_portion (float, optional) – _description_, by default 0.95

  • sizes (_type_, optional) – _description_, by default None

  • sizebar (bool, optional) – _description_, by default True

  • text_anno (_type_, optional) – _description_, by default None

  • dodge_text (bool, optional) – _description_, by default False

  • dodge_kws (_type_, optional) – _description_, by default None

  • text_kws (_type_, optional) – _description_, by default None

  • luminance (float, optional) – _description_, by default 0.48

  • text_transform (_type_, optional) – _description_, by default None

  • axis_format (str, optional) – _description_, by default “tiny”

  • max_points (int, optional) – _description_, by default 50000

  • s (str, optional) – _description_, by default “auto”

  • labelsize (int, optional) – _description_, by default 6

  • ticklabel_size (int, optional) – _description_, by default 4

  • linewidth (float, optional) – _description_, by default 0.5

  • zoomxy (float, optional) – _description_, by default 1.05

  • outline (_type_, optional) – _description_, by default None

  • outline_kws (_type_, optional) – _description_, by default None

  • outline_pad (int, optional) – _description_, by default 2

  • return_fig (bool, optional) – _description_, by default False

  • rasterized (str, optional) – _description_, by default “auto”

  • cbar_kws (_type_, optional) – _description_, by default None

  • cbar_width (int, optional) – width of colorbar, by default 3 mm

Returns:

_description_

Return type:

_type_

Raises:
  • ValueError – _description_

  • TypeError – _description_

adataviz.plotting.get_boxplot_data(adata, variable, gene, obs=None)[source]
adataviz.plotting.get_cmap(cmap)[source]
adataviz.plotting.get_genes_mean_frac(adata, obs=None, group_col='Subclass', modality='RNA', layer='mean', use_raw=False, expression_cutoff='p5', genes=None, normalize_per_cell=True, clip_norm_value=10, hypo_score=False)[source]
adataviz.plotting.has_stats(adata)[source]
adataviz.plotting.interactive_boxplot(adata, variable, gene, obs=None, palette_path=None, title=None, width=1100, height=700, show=True, renderer='notebook')[source]
adataviz.plotting.interactive_dotHeatmap(adata=None, obs=None, genes=None, group_col='Subclass', modality='RNA', title=None, use_raw=False, expression_cutoff='p5', normalize_per_cell=True, clip_norm_value=10, width=900, height=700, gene_order=None, colorscale='greens', vmin='p1', vmax='p99', show=True, reversescale=False, size_min=5, size_max=30, renderer='notebook')[source]
adataviz.plotting.interactive_embedding(adata=None, obs=None, variable=None, gene=None, coord='umap', vmin='p1', vmax='p99', cmap='jet', title=None, width=900, height=750, colors=None, palette_path=None, size=None, show=True, downsample=None, target_fill=0.05, normalize_per_cell=True, clip_norm_value=10, renderer='notebook')[source]

Plot interactive embedding plot with plotly for a given AnnData object or path of .h5ad.

Parameters:
  • adata (_type_) – _description_

  • obs (_type_, optional) – _description_, by default None

  • variable (_type_, optional) – _description_, by default None

  • gene (_type_, optional) – _description_, by default None

  • coord (str, optional) – _description_, by default “umap”

  • vmin (str, optional) – _description_, by default ‘p1’

  • vmax (str, optional) – _description_, by default ‘p99’

  • cmap (str, optional) – _description_, by default ‘jet’

  • title (_type_, optional) – _description_, by default None

  • width (int, optional) – _description_, by default 1000

  • height (int, optional) – _description_, by default 800

  • colors (_type_, optional) – _description_, by default None

  • palette_path (_type_, optional) – _description_, by default None

  • size (_type_, optional) – _description_, by default None

  • target_fill (float, optional) – _description_, by default 0.05

  • show (bool, optional) – _description_, by default True

  • renderer (str, optional) – _description_, by default “notebook” Available renderers:

  • ['plotly_mimetype' – ‘notebook’, ‘notebook_connected’, ‘kaggle’, ‘azure’, ‘colab’, ‘cocalc’, ‘databricks’, ‘json’, ‘png’, ‘jpeg’, ‘jpg’, ‘svg’, ‘pdf’, ‘browser’, ‘firefox’, ‘chrome’, ‘chromium’, ‘iframe’, ‘iframe_connected’, ‘sphinx_gallery’, ‘sphinx_gallery_png’]

  • 'jupyterlab' – ‘notebook’, ‘notebook_connected’, ‘kaggle’, ‘azure’, ‘colab’, ‘cocalc’, ‘databricks’, ‘json’, ‘png’, ‘jpeg’, ‘jpg’, ‘svg’, ‘pdf’, ‘browser’, ‘firefox’, ‘chrome’, ‘chromium’, ‘iframe’, ‘iframe_connected’, ‘sphinx_gallery’, ‘sphinx_gallery_png’]

  • 'nteract' – ‘notebook’, ‘notebook_connected’, ‘kaggle’, ‘azure’, ‘colab’, ‘cocalc’, ‘databricks’, ‘json’, ‘png’, ‘jpeg’, ‘jpg’, ‘svg’, ‘pdf’, ‘browser’, ‘firefox’, ‘chrome’, ‘chromium’, ‘iframe’, ‘iframe_connected’, ‘sphinx_gallery’, ‘sphinx_gallery_png’]

  • 'vscode' – ‘notebook’, ‘notebook_connected’, ‘kaggle’, ‘azure’, ‘colab’, ‘cocalc’, ‘databricks’, ‘json’, ‘png’, ‘jpeg’, ‘jpg’, ‘svg’, ‘pdf’, ‘browser’, ‘firefox’, ‘chrome’, ‘chromium’, ‘iframe’, ‘iframe_connected’, ‘sphinx_gallery’, ‘sphinx_gallery_png’]

:param‘notebook’, ‘notebook_connected’, ‘kaggle’, ‘azure’, ‘colab’,

‘cocalc’, ‘databricks’, ‘json’, ‘png’, ‘jpeg’, ‘jpg’, ‘svg’, ‘pdf’, ‘browser’, ‘firefox’, ‘chrome’, ‘chromium’, ‘iframe’, ‘iframe_connected’, ‘sphinx_gallery’, ‘sphinx_gallery_png’]

Returns:

_description_

Return type:

_type_

adataviz.plotting.pieplot(obs='cell_obs_with_annotation.csv', groupby='Age', outdir='figures', palette_path='~/Projects/mouse_pfc/obs/mpfc_color_palette.xlsx', order=None, explode=0.05)[source]
adataviz.plotting.plot_cluster(adata_path, ax=None, coord_base='tsne', cluster_col='MajorType', palette_path=None, coding=True, id_marker=True, output=None, show=True, figsize=(4, 3.5), sheet_name=None, ncol=None, fontsize=5, legend_fontsize=5, legend_kws=None, legend_title_fontsize=5, marker_fontsize=4, marker_pad=0.1, linewidth=0.5, axis_format='tiny', alpha=0.7, text_kws=None, **kwargs)[source]

Plot cluster.

Parameters:
  • adata_path

  • ax

  • coord_base

  • cluster_col

  • palette_path

  • coding

  • output

  • show

  • figsize

  • sheet_name

  • ncol

  • fontsize

  • legend_fontsize (int) – legend fontsize, default 5

  • legend_kws (dict) – kwargs passed to ax.legend

  • legend_title_fontsize (int) – legend title fontsize, default 5

  • marker_fontsize (int) – Marker fontsize, default 3 if id_marker is True, and coding is True. legend marker will be a circle (or rectangle) with code

  • linewidth (float) – Line width of the legend marker (circle or rectangle), default 0.5

  • kwargs (dict) – set text_anno=None to plot clustering without text annotations, coding=True to plot clustering without code annotations, set show_legend=False to remove the legend

adataviz.plotting.plot_gene(adata_path='~/Projects/BG/adata/BG.gene-CGN.h5ad', obs=None, group_col=None, gene='CADM1', query_str=None, title=None, palette_path=None, hue_norm=None, cbar_kws={'extendfrac': 0.1}, axis_format='tiny', scatter_kws={}, obsm=None, coord_base='umap', normalize_per_cell=True, stripplot=False, hypo_score=False, ylim=None, clip_norm_value=10, min_cells=3, cmap='parula', figdir='figures')[source]

Plot gene expression in a given region or group on embedding of adata.

Parameters:
  • adata_path (str, optional) – _description_, by default “~/Projects/BG/adata/BG.gene-CGN.h5ad”

  • group_col (str, optional) – _description_, for example: ‘Region’, by default None

  • gene (str, optional) – _description_, by default ‘CADM1’

  • query_str (_type_, optional) – _description_, by default None

  • title (_type_, optional) – _description_, by default None

  • palette_path (str, optional) – _description_, by default “~/Projects/BG/obs/HMBA_color_palette.xlsx”

  • obsm (str, optional) – _description_, by default “~/Projects/BG/clustering/100kb/annotated.adata.h5ad”

  • coord_base (str, optional) – _description_, by default ‘umap’

  • normalize_per_cell (bool, optional) – _description_, by default True

  • stripplot (bool, optional) – _description_, by default False

  • clip_norm_value (int, optional) – _description_, by default 10

  • min_cells (int, optional) – _description_, by default 3

  • cmap (str, optional) – _description_, by default ‘parula’

  • figdir (str, optional) – _description_, by default “figures”

adataviz.plotting.plot_genes(adata_path='/home/x-wding2/Projects/BICAN/adata/HMBA_v2/HMBA.Group.downsample_1500.h5ad', query_str=None, obs=None, group_col='Subclass', parent_col=None, modality='RNA', use_raw=True, expression_cutoff='p5', genes=None, cell_type_order=None, gene_order=None, row_cluster=False, col_cluster=False, cmap='Greens_r', group_legend=False, parent_legend=False, title=None, palette_path=None, legend_kws={'extend': 'both', 'extendfrac': 0.1, 'label': 'Mean mCG'}, normalize_per_cell=True, clip_norm_value=10, hypo_score=False, figsize=(10, 3.5), marker='o', plot_kws={}, transpose=False, outname='test.pdf')[source]

_summary_

Parameters:
  • couldbeint (_type_) – _description_

  • median (_type_) – _description_

  • meanofp5 (_type_) – _description_

  • adata_path (str, optional) – _description_, by default “/home/x-wding2/Projects/BICAN/adata/HMBA_v2/HMBA.Group.downsample_1500.h5ad”

  • query_str (_type_, optional) – _description_, by default None

  • obs (_type_, optional) – _description_, by default None

  • group_col (str, optional) – _description_, by default ‘Subclass’

  • parent_col (str, optional) – _description_, by default ‘Neighborhood’

  • modality (str, optional) – _description_, by default ‘RNA’

  • p95andsoongenes (_type_, optional) – _description_, by default None

  • cell_type_order (_type_, optional) – _description_, by default None

  • gene_order (_type_, optional) – _description_, by default None

  • row_cluster (bool, optional) – _description_, by default False

  • col_cluster (bool, optional) – _description_, by default False

  • cmap (str, optional) – _description_, by default ‘Greens_r’

  • group_legend (bool, optional) – _description_, by default False

  • parent_legend (bool, optional) – _description_, by default False

  • title (str, optional) – _description_, by default ‘test’

  • palette_path (_type_, optional) – _description_, by default None

  • obsm (_type_, optional) – _description_, by default None

  • normalize_per_cell (bool, optional) – _description_, by default True

  • clip_norm_value (int, optional) – _description_, by default 10

  • hypo_score (bool, optional) – _description_, by default False

  • figsize (tuple, optional) – _description_, by default (10, 3.5)

  • cmap – _description_, by default ‘Greens_r’

  • marker (str, optional) – _description_, by default ‘o’

  • plot_kws (dict, optional) – _description_, by default {}

  • outname (str, optional) – _description_, by default “test.pdf”

adataviz.plotting.plot_interacrive_boxplot_from_stats(adata, variable, gene, palette_path=None, title=None, width=1100, height=700)[source]
adataviz.plotting.plot_interactive_boxlot_from_data(adata, obs, variable, gene, palette_path=None, width=1100, height=700, title=None)[source]
adataviz.plotting.plot_pseudotime(pseudotime='dpt_pseudotime.tsv', groupby='Age', y='dpt_pseudotime', hue=None, figsize=(5, 3.5), outdir='figures', rotate=None, ylabel='Pseudotime', palette_path='~/Projects/mouse_pfc/obs/mpfc_color_palette.xlsx')[source]
Plot pseudotime. plot_pseudotime(figsize=(6,3.5),groupby=’MajorType’,

rotate=-45);

plot_pseudotime(figsize=(3.5,3),groupby=’CellClass’) plot_pseudotime(figsize=(3.5,3),groupby=’Age’)

Parameters:
  • pseudotime

  • groupby

  • y

  • hue

  • figsize

  • outdir

  • rotate

  • palette_path

adataviz.plotting.show_fig(fig, filename='plot')[source]
adataviz.plotting.stacked_barplot(obs='cell_obs_with_annotation.csv', groupby='Age', column='CellClass', x_order=None, y_order=None, linewidth=0.1, palette='~/Projects/mouse_pfc/obs/mpfc_color_palette.xlsx', width=None, height=None, xticklabels_kws=None, save=False, lgd_kws=None, gap=0.05, sort_by=None)[source]
Plot stacked barplto to show the cell type composition in each groupby (

such as Age, brain regions and so on.) For example: stacked_barplot(column=’MajorType’,width=3.5,height=6)

stacked_barplot(column=’CellClass’,width=3.5,height=3)

adataviz.plotting.stacked_violinplot(adata, use_genes=None, groupby='Age', cell_groups=None, parent=None, figsize=(6, 4), cmap='viridis')[source]
adataviz.plotting.use_scientific_style()[source]