SpatialTis’s plotting functions

plotting.stacked_bar

spatialtis.plotting.stacked_bar(df, groupby, percentage=True, sort_type=None, ascending=True, group_order=None, direction='vertical', size=None, title=None, xaxis_title=None, yaxis_title=None, palette=None, display=None, save=None, return_plot=False)[source]

(bokeh) Plot stacked bar

Parameters
  • df (pandas.core.frame.DataFrame) – Input data

  • groupby (Sequence[str]) – How your experiments data grouped, (Default: spatialtis.CONFIG.EXP_OBS)

  • percentage (bool) – Whether to normalize to 100%

  • sort_type (Optional[str]) – Sort the table based on the type

  • ascending (bool) – The order of sorting

  • group_order (Optional[dict]) – A Dict to control the order of axis-label eg: {‘stage’:[‘stage 1’, ‘stage 2’],’case’:[1,3,6]} The plot will display the level of stage following [‘stage 1’, ‘stage 2’] and the level of case following [1,3,6]

  • direction (str) – Options are ‘vertical’ and ‘horizontal’

  • size (Optional[Sequence[int]]) – The size of the plot in pixels

  • title (Optional[str]) – The title of the plot

  • xaxis_title (Optional[str]) – The title of X axis

  • yaxis_title (Optional[str]) – The title of Y axis

  • palette (Optional[Union[Sequence[str], str]]) – Control the color of plot, sequence of color in hex, or name of palettes

  • display (Optional[bool]) – Whether to display the plot

  • save (Optional[str]) – The path to save your plot

  • return_plot (bool) – Whether to return the plot instance

plotting.violin_plot

spatialtis.plotting.violin_plot(df, groupby, target_key, group_order=None, direction='vertical', display=None, title=None, xaxis_title=None, yaxis_title=None, size=None, save=None, palette=None, return_plot=False)[source]

(bokeh) Violin plot

Parameters
  • df (pandas.core.frame.DataFrame) – Input data

  • groupby (Sequence) – How your experiments data grouped, (Default: spatialtis.CONFIG.EXP_OBS)

  • target_key (str) – The key stores the data for plotting in AnnData.obs

  • group_order (Optional[dict]) – A Dict to control the order of axis-label eg: {‘stage’:[‘stage 1’, ‘stage 2’],’case’:[1,3,6]} The plot will display the level of stage following [‘stage 1’, ‘stage 2’] and the level of case following [1,3,6]

  • direction (str) – Options are ‘vertical’ and ‘horizontal’

  • palette (Optional[Union[Sequence[str], str]]) –

    Control the color of plot, sequence of color in hex, or name of palettes

  • xaxis_title (Optional[str]) – The title of X axis

  • yaxis_title (Optional[str]) – The title of Y axis

  • size (Optional[Sequence[int]]) – The size of the plot in pixels

  • display (Optional[bool]) – Whether to display the plot

  • title (Optional[str]) – The title of the plot

  • save (Optional[str]) – The path to save your plot

  • return_plot (bool) – Whether to return the plot instance

plotting.heatmap

spatialtis.plotting.heatmap(df, row_label=None, col_label=None, row_colors=None, col_colors=None, palette=None, colorbar_type='bar', categorical_colorbar_text=None, row_colors_legend_bbox=None, col_colors_legend_bbox=None, colorbar_bbox=None, save=None, display=None, return_plot=False, **kwargs)[source]

(matplotlib) A higher wrapper for seaborn’s clustermap

The order of cateforical_colorbar_text match to the order of palette

Parameters
  • df (pandas.core.frame.DataFrame) – Input data, all data should store in data part, annotations should store in MultiIndex

  • row_label (Optional[str]) – Which level to plot row text

  • col_label (Optional[str]) – Which level to plot col text

  • row_colors (Optional[Union[Sequence[str], str]]) – Which level to plot row colors

  • col_colors (Optional[Union[Sequence[str], str]]) – Which level to plot col colors

  • palette (Optional[Union[Sequence[str], str]]) –

    Control the color of plot, sequence of color in hex, or name of palettes

  • colorbar_type (str) – Options are ‘continuous’ and ‘categorical’

  • categorical_colorbar_text (Optional[Union[Sequence[str], str]]) – If ‘categorical’, the text need to be provided

  • row_colors_legend_bbox (Optional[Sequence[float]]) – Adjust the locations of row colors legend

  • col_colors_legend_bbox (Optional[Sequence[float]]) – Adjust the locations of col colors legend

  • colorbar_bbox (Optional[Sequence[float]]) – Adjust the locations of colorbar

  • display (Optional[bool]) – Whether to display the plot

  • save (Optional[Union[pathlib.Path, str]]) – The path to save your plot

  • return_plot (bool) – Whether to return the plot instance

plotting.dotplot

spatialtis.plotting.dotplot(matrix, colors='#376B6D', xlabels=None, ylabels=None, xlabel_rotation=90, ylabel_rotation=0, legend_title=None, annotated=False, alpha=0.5, display=None, return_plot=False, title=None, save=None)[source]

(matplotlib) Dotplot

Parameters
  • matrix (Sequence) – Matrix array of values

  • colors (Union[str, Sequence]) – The color of every dot

  • xlabels (Optional[Sequence]) – The labels marked on X axis

  • ylabels (Optional[Sequence]) – The labels marked on Y axis

  • annotated (bool) – {annotated}

  • xlabel_rotation (int) – Number of degree to rotate X-axis’s label

  • ylabel_rotation (int) – Number of degree to rotate Y-axis’s label

  • legend_title (Optional[str]) – The title of legend

  • alpha (float) – Alpha value for opacity

  • title (Optional[str]) – The title of the plot

  • display (Optional[bool]) – Whether to display the plot

  • save (Optional[Union[str, pathlib.Path]]) – The path to save your plot

  • return_plot (bool) – Whether to return the plot instance

plotting.tri_dotplot

spatialtis.plotting.tri_dotplot(diagonal_arr, colors='#376B6D', labels=None, xlabel_rotation=90, ylabel_rotation=0, legend_title=None, annotate=False, alpha=0.5, display=None, title=None, save=None, return_plot=False)[source]

(matplotlib) Triangular dotplot

This input diagnol array should look like this

   A B C D
A  1 2 3 4
B  1 2 3
C  1 2
D  1
Parameters
  • diagonal_arr (Sequence) – The diagonal array

  • labels (Optional[Sequence]) – Labels will be marked in x and y axis

  • colors (Union[str, Sequence]) – Colors of the dot

  • xlabel_rotation (int) – Number of degree to rotate X-axis’s label

  • ylabel_rotation (int) – Number of degree to rotate Y-axis’s label

  • legend_title (Optional[str]) – The title of legend

  • annotate (bool) – Whether to show value number

  • alpha (float) – Alpha value for opacity

  • display (Optional[bool]) – Whether to display the plot

  • title (Optional[str]) – The title of the plot

  • save (Optional[Union[str, pathlib.Path]]) – The path to save your plot

  • return_plot (bool) – Whether to return the plot instance

plotting.sankey

spatialtis.plotting.sankey(nodes, nodes_colors, links, renderer='canvas', theme='white', size=(900, 500), title=None, display=None, save=None, return_plot=False)[source]

(pyecharts) Sankey plot

Parameters
  • nodes (Sequence) – All the nodes

  • nodes_colors (Sequence) – The color for each node

  • links (Sequence) – Connections between nodes

  • renderer (str) – Options are “canvas” and “svg”; “svg” is not perfect at this moment.

  • theme (str) – Please go to theme for details

  • size (Sequence) – The size of the plot in pixels

  • title (Optional[str]) – The title of the plot

  • display (Optional[bool]) – Whether to display the plot

  • save (Optional[Union[str, pathlib.Path]]) – The path to save your plot

  • return_plot (bool) – Whether to return the plot instance

plotting.graph_plot

spatialtis.plotting.graph_plot(nodes, edges, nodes_types=None, edges_types=None, node_size=1, edge_size=0.7, size=(15, 15), palette=None, display=None, return_plot=False, title=None, save=None)[source]

(matplotlib) Graph visualization

Parameters
  • nodes – List of nodes

  • edges – List of edges

  • nodes_types – The type of every node

  • edges_types – The type of every edge

  • node_size (Union[float, int]) – The size of node

  • edge_size (Union[float, int]) – The size of edge width

  • size (Sequence) – The size of the plot in pixels

  • palette (Optional[Sequence]) –

    Control the color of plot, sequence of color in hex, or name of palettes

  • title (Optional[str]) – The title of the plot

  • display (Optional[bool]) – Whether to display the plot

  • save (Optional[Union[str, pathlib.Path]]) – The path to save your plot

  • return_plot (bool) – Whether to return the plot instance

plotting.graph_plot_interactive

spatialtis.plotting.graph_plot_interactive(nodes, edges, nodes_types=None, edges_types=None, node_size=1, edge_size=0.5, size=(800, 800), renderer='canvas', theme='white', display=None, return_plot=False, title=None, save=None)[source]

(pyecharts) Graph visualization

Parameters
  • nodes (Sequence) – List of nodes

  • edges (Sequence) – List of edges

  • nodes_types (Optional[Sequence]) – The type of every node

  • edges_types (Optional[Sequence]) – The type of every edge

  • node_size (Union[float, int]) – The size of node

  • edge_size (Union[float, int]) – The size of edge width

  • size (Sequence) – The size of the plot in pixels

  • renderer (str) – Options are “canvas” and “svg”; “svg” is not perfect at this moment.

  • theme (str) –

    Please go to theme for details

  • title (Optional[str]) – The title of the plot

  • display (Optional[bool]) – Whether to display the plot

  • save (Optional[Union[str, pathlib.Path]]) – The size of the plot in pixels

  • return_plot (bool) – Whether to return the plot instance

plotting.DotMatrix

class spatialtis.plotting.DotMatrix(matrix=None, dot_color=None, dot_size=None, xlabels=None, ylabels=None, xlabel_rotation=90, ylabel_rotation=0, show_ticks=True, xaxis_title=None, yaxis_title=None, matrix_cbar_text=None, dot_cbar_text=None, matrix_cbar_title=None, dot_cbar_title=None, size_legend_title=None, matrix_palette=None, dot_palette=None, display=None, title=None, save=None)[source]

(matplotlib) Dot matrix plot

Parameters
  • matrix (Optional[Sequence]) – The value to control the color of matrix

  • dot_color (Optional[Sequence]) – The value to control the dot color

  • dot_size (Optional[Sequence]) – The value to control the dot size

  • xlabels (Optional[Sequence]) – The labels marked on X axis

  • ylabels (Optional[Sequence]) – The labels marked on Y axis

  • xlabel_rotation (int) – Number of degree to rotate X-axis’s label

  • ylabel_rotation (int) – Number of degree to rotate Y-axis’s label

  • show_ticks (bool) – Whether to show the minor ticks

  • xaxis_title (Optional[str]) – The title of X axis

  • yaxis_title (Optional[str]) – The title of Y axis

  • matrix_cbar_text (Optional[Mapping]) – How to map the rect colorbar to annotation text

  • dot_cbar_text (Optional[Mapping]) – How to map the dot colorbar to annotation text

  • matrix_cbar_title (Optional[str]) – The title of the rect colorbar

  • dot_cbar_title (Optional[str]) – The title of dot colorbar

  • size_legend_title (Optional[str]) – Title of the size legend

  • matrix_palette (Optional[Sequence]) – Control the color of rect

  • dot_palette (Optional[Sequence]) – Control the color of dot

  • display (Optional[bool]) – Whether to display the plot

  • title (Optional[str]) – The title of the plot

  • save (Optional[Union[str, pathlib.Path]]) – The path to save your plot

plotting.TriDotMatrix

class spatialtis.plotting.TriDotMatrix(diagonal_block=None, diagonal_dot_color=None, diagonal_dot_size=None, labels=None, xlabel_rotation=90, ylabel_rotation=0, xaxis_title=None, yaxis_title=None, show_ticks=True, block_cbar_text=None, dot_cbar_text=None, block_cbar_title=None, dot_cbar_title=None, size_legend_title=None, block_palette=None, dot_palette=None, display=None, title=None, save=None)[source]

(matplotlib) Triangular dot plot

This input diagnol array should look like this

   A B C D
A  1 2 3 4
B  1 2 3
C  1 2
D  1
Parameters
  • diagonal_block (Optional[Sequence]) – the diagonal array for block

  • diagonal_dot_color (Optional[Sequence]) –

  • diagonal_dot_size (Optional[Sequence]) –

  • labels (Optional[Sequence]) – labels will be marked in x and y axis

  • xlabel_rotation (int) – Number of degree to rotate X-axis’s label

  • ylabel_rotation (int) – Number of degree to rotate Y-axis’s label

  • xaxis_title (Optional[str]) – The title of X axis

  • yaxis_title (Optional[str]) – The title of Y axis

  • show_ticks (bool) – Whether to show the minor ticks

  • block_cbar_text (Optional[Sequence]) – How to map the rect colorbar to annotation text

  • dot_cbar_text (Optional[Sequence]) – How to map the dot colorbar to annotation text

  • block_cbar_title (Optional[str]) – The title of the rect colorbar

  • dot_cbar_title (Optional[str]) – The title of dot colorbar

  • size_legend_title (Optional[str]) – Title of the size legend

  • block_palette (Optional[Sequence]) – Control the color of rect

  • dot_palette (Optional[Sequence]) – Control the color of dot

  • display (Optional[bool]) – Whether to display the plot

  • title (Optional[str]) – The title of the plot

  • save (Optional[Union[str, pathlib.Path]]) – The path to save your plot