spatiomic.plot¶
Plotting functions from the plot submodule.
Functions¶
|
Create a histogram of the mean of the cluster contributors. |
|
Create half of a volcano plot to show the increased contributors to a cluster. |
|
Plot the image with the clusters shown in colors and a colorbar. |
|
Plot a legend for the clusters. |
|
Plot the location of each cluster in a labelled image individually. |
|
Scatter the points and color them according to the clusters. |
|
Plot the image with the clusters shown in colors and a colorbar. |
|
Return a colormap with the provided number of colors. |
|
Plot a connectivity graph. |
|
Plot the expression of each marker in an image. |
|
Plot the change in the MSSIM before and after registration. |
|
Plot the distribution violinplot and histogram for SSIM scores before and after registration. |
|
Save the cluster image to a file. |
|
Save the image with the clusters shown in colors. |
|
Plot a self-organizing map in 2D with corresponding clusters. |
|
Create and a figure of the distance between SOM nodes. |
|
Visualize marker expressions of all markers. |
|
Plot a graph of spatial cluster-cluster relationships. |
|
Create a volcano plot of the data. |
Package Contents¶
- spatiomic.plot.cluster_contributor_histogram(data, channel_names, max_data=None, bin_count=10, scaling_factor_y=100.0)¶
Create a histogram of the mean of the cluster contributors.
- spatiomic.plot.cluster_contributors(data, cluster_idx, cluster_column='group', channel_column='marker', log2_fold_change_column='log2_fold_change', log10_p_value_column='log10_p_value', p_value_column=None, increased_color='#AA3333', neutral_color='#AAAAAA', increased_p_value_threshold=0.05, increased_log2_fold_change_threshold=1.0, show_neutral=True, fontsize=10, mean_max=1.0, size_increased=20, size_neutral=20, annotate_increased=True, annotate_neutral=False, figsize=(8, 5), title=None)¶
Create half of a volcano plot to show the increased contributors to a cluster.
Warning
When only p-values are available, the -log10(p-value) will be calculated with a small pseudo count
of 1e-38 to avoid log(0) errors.
- Parameters:
data (pd.DataFrame) – The data, output from
so.tool.get_stats
.cluster_idx (int) – The index of the cluster to plot.
cluster_column (str) – The column name for the cluster. Defaults to “group”.
channel_column (str) – The column name for the channels. Defaults to “marker”.
log2_fold_change_column (str, optional) – The column name for the log2 fold change. Defaults to “log2_fold_change”.
log10_p_value_column (Optional[str], optional) – The column name for the log10 p value. Defaults to “log10_p_value”.
p_value_column (Optional[str], optional) – The column name for the p value. Defaults to None.
increased_color (str, optional) – The color for the increase. Defaults to “red”.
neutral_color (str, optional) – The color for the non-significant. Defaults to “grey”.
significant_mean_threshold (Optional[float], optional) – The threshold for the mean. Defaults to None.
significant_p_value_threshold (float, optional) – The threshold for the p value. Defaults to 0.05.
significant_log2_fold_change_threshold (float, optional) – The threshold for the log2 fold change. Defaults to 1.0.
show_neutral (bool, optional) – Whether to show the neutral points. Defaults to True.
fontsize (int, optional) – The font size for the annotations. Defaults to 10.
mean_max (float, optional) – The maximum value for the mean. Defaults to 1.0.
annotate_increased (bool, optional) – Whether to shwo the names of the significant values. Defaults to True.
annotate_neutral (bool, optional) – Whether to annotate the neutral values. Defaults to False.
figsize (Tuple[Union[int, float], Union[int, float]], optional) – The size of the figure. Defaults to (8, 5).
title (Optional[str], optional) – The title of the plot. Defaults to None.
increased_p_value_threshold (float)
increased_log2_fold_change_threshold (float)
size_increased (int)
size_neutral (int)
- Returns:
The figure.
- Return type:
plt.Figure
- spatiomic.plot.cluster_image(image, colormap=None)¶
Plot the image with the clusters shown in colors and a colorbar.
- Parameters:
image (NDArray) – The image of the clusters.
colormap (ListedColormap, optional) – The colormap to use. Defaults to None.
- Returns:
The figure.
- Return type:
plt.Figure
- spatiomic.plot.cluster_legend(cluster_count, cluster_labels=None, colormap=None, figsize=None)¶
Plot a legend for the clusters.
- Parameters:
cluster_count (int) – The number of clusters.
cluster_labels (Optional[List[str]], optional) – The labels for the clusters. Defaults to None.
colormap (ListedColormap, optional) – The colormap to use. Defaults to None.
figsize (Optional[Union[int, float, Tuple[Union[int, float], Union[int, float]]], optional) – The figure size. Defaults to None.
- Returns:
The figure.
- Return type:
plt.Figure
- spatiomic.plot.cluster_location(image, title='Isolated Clusters', cluster_title='Cluster', cluster_labels=None, figsize=None)¶
Plot the location of each cluster in a labelled image individually.
- Parameters:
image (NDArray) – The clustered image.
title (str, optional) – Title for the figure. Defaults to “Isolated Clusters”.
cluster_title (str, optional) – Text to be preprended to the cluster number. Defaults to “Cluster”.
cluster_labels (Optional[List[Union[str, int]]], optional) – Custom names for the clusters. Defaults to None.
figsize (Optional[Tuple[Union[int, float], Union[int, float]]], optional) – The size of the figure. Defaults to None.
- Returns:
The figure.
- Return type:
plt.Figure
- spatiomic.plot.cluster_scatter(data, clusters, title_x='Dimension 1', title_y='Dimension 2', figsize=None, colormap=None)¶
Scatter the points and color them according to the clusters.
- Parameters:
data (NDArray) – The data to be scattered.
clusters (Union[NDArray, List]) – The clusters for the data.
title_x (str, optional) – The title for the x-axis. Defaults to “Dimension 1”.
title_y (str, optional) – The title for the y-axis. Defaults to “Dimension 2”.
colormap (Optional[ListedColormap], optional) – The colormap to use. Defaults to None.
figsize (Optional[Tuple[Union[int, float], Union[int, float]]])
- Returns:
The figure.
- Return type:
plt.Figure
- spatiomic.plot.cluster_selection(image, clusters, colormap=None)¶
Plot the image with the clusters shown in colors and a colorbar.
- Parameters:
image (NDArray) – The clustered image.
clusters (Union[NDArray, List[int]]) – Which clusters to show. All others will be collapsed into a single black background cluster.
colormap (Optional[ListedColormap], optional) – The colormap to use. Defaults to None.
- Returns:
The figure.
- Return type:
plt.Figure
- spatiomic.plot.colormap(color_count, flavor='random_hls', color_override=None, use_system_background_list=True, seed=0)¶
Return a colormap with the provided number of colors.
- Parameters:
color_count (int, optional) – The number of colors needed.
flavor (Literal["random_hls", "random_hls"], optional) – The method for choosing colors. Either generates random HLS values with luminosity between 30 and 85 and saturation between 30 and 100 or uses the glasbey light color palette from colorcet (up to 100 colors). Defaults to “random_hls”.
color_override (Optional[Dict[int, str]], optional) – A dictionary of cluster indices and colors to override the default colors. Defaults to None.
use_system_background_list (bool, optional) – Whether to adjust the colors of background clusters based on the environment variables
SPATIOMIC_BG_CLUSTER_LIST
andSPATIOMIC_BG_COLOR
. Defaults to True.seed (int, optional) – The seed for the random color generation. Defaults to 0.
- Returns:
Colormap of the first color_count colors from the spatiomic colormap.
- Return type:
ListedColormap
- spatiomic.plot.connectivity_graph(graph, title='Connectivity Graph', clusters=None, cluster_legend=False, node_size=50, figsize=(7.5, 7.5), colormap=None, seed=0)¶
Plot a connectivity graph.
- Parameters:
graph (Graph) – The graph to be plotted.
title (str, optional) – Title for the figure. Defaults to “Connectivity Graph”.
clusters (Optional[NDArray], optional) – clusters for each vertex of the graph to be displayed. Defaults to None.
cluster_legend (bool, optional) – Whether to include a legend for the clusters. Defaults to False.
node_size (int, optional) – Size of the nodes in the figure. Defaults to 50.
figsize (Tuple[Union[int, float], Union[int, float]], optional) – Size of the figure. Defaults to (7.5, 7.5).
colormap (Optional[ListedColormap], optional) – The colormap to use. Defaults to None.
seed (int, optional) – Seed for the layout algorithm, only used if graphviz is not installed. Defaults to 0.
- Returns:
A figure of the graph, plotted in 2D.
- Return type:
plt.Figure
- spatiomic.plot.marker_expression(image, title='Marker Expression', channel_names=None, min_value=None, max_value=None, figsize=None, colormap=None)¶
Plot the expression of each marker in an image.
- Parameters:
image (NDArray) – The XYC image with the markers.
title (str, optional) – The title of the plot. Defaults to “Marker Expression”.
channel_names (Optional[List[Union[str, int]]], optional) – The names of the channels. Defaults to None.
min_value (Optional[float], optional) – The minimum value for the colormap. Defaults to None.
max_value (Optional[float], optional) – The maximum value for the colormap. Defaults to None.
figsize (Optional[Tuple[Union[int, float], Union[int, float]]], optional) – The size of the figure. Defaults to None.
colormap (Optional[ListedColormap], optional) – The colormap to use. Defaults to None.
- Returns:
The figure.
- Return type:
plt.Figure
- spatiomic.plot.registration_similarity(df_similarity, before_label='Before Registration', after_label='After Registration', title='Structural Similarity', point_size=70, xtick_min=0.0, xtick_max=1.0)¶
Plot the change in the MSSIM before and after registration.
- Parameters:
df (pd.DataFrame) – [description]
before_label (str, optional) – [description]. Defaults to “Before Registration”.
after_label (str, optional) – [description]. Defaults to “After Registration”.
title (Optional[str], optional) – [description]. Defaults to “Structural Similarity”.
point_size (int, optional) – [description]. Defaults to 70.
xtick_min (float, optional) – [description]. Defaults to 0.0.
xtick_max (float, optional) – [description]. Defaults to 1.0.
df_similarity (pandas.DataFrame)
- Returns:
[description]
- Return type:
plt.Figure
- spatiomic.plot.registration_slope(df_similarity, before_label='Before Registration', after_label='After Registration', ssim_label='SSIM', title='Change in Structural Similarity')¶
Plot the distribution violinplot and histogram for SSIM scores before and after registration.
- Parameters:
df_similarity (pd.DataFrame) – [description]
before_label (str, optional) – [description]. Defaults to “Before Registration”.
after_label (str, optional) – [description]. Defaults to “After Registration”.
ssim_label (str, optional) – [description]. Defaults to “SSIM”.
title (Optional[str], optional) – [description]. Defaults to “Change in Structural Similarity”.
- Returns:
[description]
- Return type:
plt.Figure
- spatiomic.plot.save_cluster_image(image, save_path, colormap=None)¶
Save the cluster image to a file.
- Parameters:
image (NDArray) – The image of the clusters to save.
save_path (str) – The path to save the image to.
colormap (ListedColormap, optional) – The colormap to use. Defaults to None.
- Return type:
None
- spatiomic.plot.save_cluster_selection(image, save_path, clusters, colormap=None)¶
Save the image with the clusters shown in colors.
- spatiomic.plot.som_clusters(som, clusters, title='Self-Organizing Map Clusters', colormap=None)¶
Plot a self-organizing map in 2D with corresponding clusters.
- Parameters:
- Returns:
The figure.
- Return type:
plt.Figure
- spatiomic.plot.som_distance(som)¶
Create and a figure of the distance between SOM nodes.
- Parameters:
som (som) – The self-organizing map.
- Returns:
The figure.
- Return type:
plt.Figure
- spatiomic.plot.som_marker_expression(data, channel_names=None, figsize=None)¶
Visualize marker expressions of all markers.
- Parameters:
- Returns:
The figure.
- Return type:
plt.Figure
- spatiomic.plot.spatial_graph(graph, reference_graph=None, edge_threshold=0.0, remove_isolated_nodes=True, edge_stroke_weight_multiplier=10.0, edge_color_multiplier=0.6, title=None, seed=0)¶
Plot a graph of spatial cluster-cluster relationships.
- Parameters:
graph (Union[DiGraph, Graph]) – The neighborhood graph.
reference_graph (Optional[Union[DiGraph, Graph]], optional) – The reference graph. Defaults to None.
edge_threshold (float, optional) – The threshold for the edge weights. Defaults to 0.0.
remove_isolated_nodes (bool, optional) – Whether to remove isolated nodes. Defaults to True.
edge_stroke_weight_multiplier (float, optional) – The multiplier for the edge weights for stroke width. Defaults to 10.0.
edge_color_multiplier (float, optional) – The multiplier for the edge weights for color. Defaults to 0.6.
title (str, optional) – The title of the plot. Defaults to None.
seed (int, optional) – Seed for the layout algorithm, only used if graphviz is not installed. Defaults to 0.
- Returns:
The figure.
- Return type:
plt.Figure
- spatiomic.plot.volcano(data, channel_column, log2_fold_change_column='log2_fold_change', log10_p_value_column='log10_p_value', p_value_column=None, increased_color='#AA3333', decreased_color='#3333AA', neutral_color='#AAAAAA', significant_p_value_threshold=0.05, significant_log2_fold_change_threshold=1.0, annotate_significant=True, annotate_neutral=False, size_significant=20, size_neutral=20, fontsize=8, figsize=(10, 5), title=None)¶
Create a volcano plot of the data.
- Parameters:
data (pd.DataFrame) – The data.
channel_column (str) – The column name for the channel.
log2_fold_change_column (str, optional) – The column name for the log2 fold change. Defaults to “log2_fold_change”.
log10_p_value_column (Optional[str], optional) – The column name for the log10 p value. Defaults to “log10_p_value”.
p_value_column (Optional[str], optional) – The column name for the p value. Defaults to None.
increased_color (str, optional) – The color for the increase. Defaults to “#AA3333”.
decreased_color (str, optional) – The color for the decrease. Defaults to “#3333AA”.
neutral_color (str, optional) – The color for the non-significant. Defaults to “#AAAAAA”.
significant_p_value_threshold (float, optional) – The threshold for the p value. Defaults to 0.05.
significant_log2_fold_change_threshold (float, optional) – The threshold for the log2 fold change. Defaults to 1.0.
annotate_significant (bool, optional) – Whether to annotate the significant values. Defaults to True.
annotate_neutral (bool, optional) – Whether to annotate the neutral values. Defaults to False.
size_significant (int, optional) – The size of the significant points. Defaults to 20.
size_neutral (int, optional) – The size of the neutral points. Defaults to 20.
fontsize (int, optional) – The font size for the annotations. Defaults to 8.
figsize (Tuple[Union[int, float], Union[int, float]], optional) – The size of the figure. Defaults to (10, 5).
title (Optional[str], optional) – The title of the plot. Defaults to None.
- Returns:
The figure.
- Return type:
plt.Figure