spatiomic.plot ============== .. py:module:: spatiomic.plot .. autoapi-nested-parse:: Plotting functions from the plot submodule. Functions --------- .. autoapisummary:: spatiomic.plot.cluster_contributor_histogram spatiomic.plot.cluster_contributors spatiomic.plot.cluster_image spatiomic.plot.cluster_legend spatiomic.plot.cluster_location spatiomic.plot.cluster_scatter spatiomic.plot.cluster_selection spatiomic.plot.colormap spatiomic.plot.connectivity_graph spatiomic.plot.marker_expression spatiomic.plot.registration_similarity spatiomic.plot.registration_slope spatiomic.plot.save_cluster_image spatiomic.plot.save_cluster_selection spatiomic.plot.som_clusters spatiomic.plot.som_distance spatiomic.plot.som_marker_expression spatiomic.plot.spatial_graph spatiomic.plot.volcano Package Contents ---------------- .. py:function:: 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. :param data: The data of a single cluster. :type data: NDArray :param channel_names: The channel names. :type channel_names: List[str] :param scaling_factor_y: The scaling factor for the y-axis. Defaults to 100.0. :type scaling_factor_y: float, optional :returns: The figure. :rtype: plt.Figure .. py:function:: 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. :param data: The data, output from `so.tool.get_stats`. :type data: pd.DataFrame :param cluster_idx: The index of the cluster to plot. :type cluster_idx: int :param cluster_column: The column name for the cluster. Defaults to "group". :type cluster_column: str :param channel_column: The column name for the channels. Defaults to "marker". :type channel_column: str :param log2_fold_change_column: The column name for the log2 fold change. Defaults to "log2_fold_change". :type log2_fold_change_column: str, optional :param log10_p_value_column: The column name for the log10 p value. Defaults to "log10_p_value". :type log10_p_value_column: Optional[str], optional :param p_value_column: The column name for the p value. Defaults to None. :type p_value_column: Optional[str], optional :param increased_color: The color for the increase. Defaults to "red". :type increased_color: str, optional :param neutral_color: The color for the non-significant. Defaults to "grey". :type neutral_color: str, optional :param significant_mean_threshold: The threshold for the mean. Defaults to None. :type significant_mean_threshold: Optional[float], optional :param significant_p_value_threshold: The threshold for the p value. Defaults to 0.05. :type significant_p_value_threshold: float, optional :param significant_log2_fold_change_threshold: The threshold for the log2 fold change. Defaults to 1.0. :type significant_log2_fold_change_threshold: float, optional :param show_neutral: Whether to show the neutral points. Defaults to True. :type show_neutral: bool, optional :param fontsize: The font size for the annotations. Defaults to 10. :type fontsize: int, optional :param mean_max: The maximum value for the mean. Defaults to 1.0. :type mean_max: float, optional :param annotate_increased: Whether to shwo the names of the significant values. Defaults to True. :type annotate_increased: bool, optional :param annotate_neutral: Whether to annotate the neutral values. Defaults to False. :type annotate_neutral: bool, optional :param figsize: The size of the figure. Defaults to (8, 5). :type figsize: Tuple[Union[int, float], Union[int, float]], optional :param title: The title of the plot. Defaults to None. :type title: Optional[str], optional :returns: The figure. :rtype: plt.Figure .. py:function:: cluster_image(image, colormap = None) Plot the image with the clusters shown in colors and a colorbar. :param image: The image of the clusters. :type image: NDArray :param colormap: The colormap to use. Defaults to None. :type colormap: ListedColormap, optional :returns: The figure. :rtype: plt.Figure .. py:function:: cluster_legend(cluster_count, cluster_labels = None, colormap = None, figsize = None) Plot a legend for the clusters. :param cluster_count: The number of clusters. :type cluster_count: int :param cluster_labels: The labels for the clusters. Defaults to None. :type cluster_labels: Optional[List[str]], optional :param colormap: The colormap to use. Defaults to None. :type colormap: ListedColormap, optional :param figsize: The figure size. Defaults to None. :type figsize: Optional[Union[int, float, Tuple[Union[int, float], Union[int, float]]], optional :returns: The figure. :rtype: plt.Figure .. py:function:: 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. :param image: The clustered image. :type image: NDArray :param title: Title for the figure. Defaults to "Isolated Clusters". :type title: str, optional :param cluster_title: Text to be preprended to the cluster number. Defaults to "Cluster". :type cluster_title: str, optional :param cluster_labels: Custom names for the clusters. Defaults to None. :type cluster_labels: Optional[List[Union[str, int]]], optional :param figsize: The size of the figure. Defaults to None. :type figsize: Optional[Tuple[Union[int, float], Union[int, float]]], optional :returns: The figure. :rtype: plt.Figure .. py:function:: 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. :param data: The data to be scattered. :type data: NDArray :param clusters: The clusters for the data. :type clusters: Union[NDArray, List] :param title_x: The title for the x-axis. Defaults to "Dimension 1". :type title_x: str, optional :param title_y: The title for the y-axis. Defaults to "Dimension 2". :type title_y: str, optional :param colormap: The colormap to use. Defaults to None. :type colormap: Optional[ListedColormap], optional :returns: The figure. :rtype: plt.Figure .. py:function:: cluster_selection(image, clusters, colormap = None) Plot the image with the clusters shown in colors and a colorbar. :param image: The clustered image. :type image: NDArray :param clusters: Which clusters to show. All others will be collapsed into a single black background cluster. :type clusters: Union[NDArray, List[int]] :param colormap: The colormap to use. Defaults to None. :type colormap: Optional[ListedColormap], optional :returns: The figure. :rtype: plt.Figure .. py:function:: 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. :param color_count: The number of colors needed. :type color_count: int, optional :param flavor: 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". :type flavor: Literal["random_hls", "random_hls"], optional :param color_override: A dictionary of cluster indices and colors to override the default colors. Defaults to None. :type color_override: Optional[Dict[int, str]], optional :param use_system_background_list: Whether to adjust the colors of background clusters based on the environment variables `SPATIOMIC_BG_CLUSTER_LIST` and `SPATIOMIC_BG_COLOR`. Defaults to True. :type use_system_background_list: bool, optional :param seed: The seed for the random color generation. Defaults to 0. :type seed: int, optional :returns: Colormap of the first color_count colors from the spatiomic colormap. :rtype: ListedColormap .. py:function:: 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. :param graph: The graph to be plotted. :type graph: Graph :param title: Title for the figure. Defaults to "Connectivity Graph". :type title: str, optional :param clusters: clusters for each vertex of the graph to be displayed. Defaults to None. :type clusters: Optional[NDArray], optional :param cluster_legend: Whether to include a legend for the clusters. Defaults to False. :type cluster_legend: bool, optional :param node_size: Size of the nodes in the figure. Defaults to 50. :type node_size: int, optional :param figsize: Size of the figure. Defaults to (7.5, 7.5). :type figsize: Tuple[Union[int, float], Union[int, float]], optional :param colormap: The colormap to use. Defaults to None. :type colormap: Optional[ListedColormap], optional :param seed: Seed for the layout algorithm, only used if graphviz is not installed. Defaults to 0. :type seed: int, optional :returns: A figure of the graph, plotted in 2D. :rtype: plt.Figure .. py:function:: 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. :param image: The XYC image with the markers. :type image: NDArray :param title: The title of the plot. Defaults to "Marker Expression". :type title: str, optional :param channel_names: The names of the channels. Defaults to None. :type channel_names: Optional[List[Union[str, int]]], optional :param min_value: The minimum value for the colormap. Defaults to None. :type min_value: Optional[float], optional :param max_value: The maximum value for the colormap. Defaults to None. :type max_value: Optional[float], optional :param figsize: The size of the figure. Defaults to None. :type figsize: Optional[Tuple[Union[int, float], Union[int, float]]], optional :param colormap: The colormap to use. Defaults to None. :type colormap: Optional[ListedColormap], optional :returns: The figure. :rtype: plt.Figure .. py:function:: 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. :param df: [description] :type df: pd.DataFrame :param before_label: [description]. Defaults to "Before Registration". :type before_label: str, optional :param after_label: [description]. Defaults to "After Registration". :type after_label: str, optional :param title: [description]. Defaults to "Structural Similarity". :type title: Optional[str], optional :param point_size: [description]. Defaults to 70. :type point_size: int, optional :param xtick_min: [description]. Defaults to 0.0. :type xtick_min: float, optional :param xtick_max: [description]. Defaults to 1.0. :type xtick_max: float, optional :returns: [description] :rtype: plt.Figure .. py:function:: 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. :param df_similarity: [description] :type df_similarity: pd.DataFrame :param before_label: [description]. Defaults to "Before Registration". :type before_label: str, optional :param after_label: [description]. Defaults to "After Registration". :type after_label: str, optional :param ssim_label: [description]. Defaults to "SSIM". :type ssim_label: str, optional :param title: [description]. Defaults to "Change in Structural Similarity". :type title: Optional[str], optional :returns: [description] :rtype: plt.Figure .. py:function:: save_cluster_image(image, save_path, colormap = None) Save the cluster image to a file. :param image: The image of the clusters to save. :type image: NDArray :param save_path: The path to save the image to. :type save_path: str :param colormap: The colormap to use. Defaults to None. :type colormap: ListedColormap, optional .. py:function:: save_cluster_selection(image, save_path, clusters, colormap = None) Save the image with the clusters shown in colors. :param image: The image of the clusters. :type image: NDArray :param save_path: The path to save the image to. :type save_path: str :param clusters: The clusters to show. :type clusters: Union[NDArray, List[int]] :param colormap: The colormap to use. Defaults to None. :type colormap: Optional[ListedColormap], optional .. py:function:: som_clusters(som, clusters, title = 'Self-Organizing Map Clusters', colormap = None) Plot a self-organizing map in 2D with corresponding clusters. :param som: The self-organizing map. :type som: som :param clusters: The clusters. :type clusters: NDArray :param title: The title for the plot. Defaults to "Self-Organizing Map Clusters". :type title: str, optional :param colormap: Custom colormap. Defaults to None. :type colormap: Optional[ListedColormap], optional :returns: The figure. :rtype: plt.Figure .. py:function:: som_distance(som) Create and a figure of the distance between SOM nodes. :param som: The self-organizing map. :type som: som :returns: The figure. :rtype: plt.Figure .. py:function:: som_marker_expression(data, channel_names = None, figsize = None) Visualize marker expressions of all markers. :param data: The multi-channel image. :type data: NDArray :param channel_names: Custom names for the channels. Defaults to None. :type channel_names: Optional[List[Union[str, int]]], optional :param figsize: The size of the figure. Defaults to None. :type figsize: Optional[Tuple[Union[int, float], Union[int, float]]], optional :returns: The figure. :rtype: plt.Figure .. py:function:: 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. :param graph: The neighborhood graph. :type graph: Union[DiGraph, Graph] :param reference_graph: The reference graph. Defaults to None. :type reference_graph: Optional[Union[DiGraph, Graph]], optional :param edge_threshold: The threshold for the edge weights. Defaults to 0.0. :type edge_threshold: float, optional :param remove_isolated_nodes: Whether to remove isolated nodes. Defaults to True. :type remove_isolated_nodes: bool, optional :param edge_stroke_weight_multiplier: The multiplier for the edge weights for stroke width. Defaults to 10.0. :type edge_stroke_weight_multiplier: float, optional :param edge_color_multiplier: The multiplier for the edge weights for color. Defaults to 0.6. :type edge_color_multiplier: float, optional :param title: The title of the plot. Defaults to None. :type title: str, optional :param seed: Seed for the layout algorithm, only used if graphviz is not installed. Defaults to 0. :type seed: int, optional :returns: The figure. :rtype: plt.Figure .. py:function:: 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. :param data: The data. :type data: pd.DataFrame :param channel_column: The column name for the channel. :type channel_column: str :param log2_fold_change_column: The column name for the log2 fold change. Defaults to "log2_fold_change". :type log2_fold_change_column: str, optional :param log10_p_value_column: The column name for the log10 p value. Defaults to "log10_p_value". :type log10_p_value_column: Optional[str], optional :param p_value_column: The column name for the p value. Defaults to None. :type p_value_column: Optional[str], optional :param increased_color: The color for the increase. Defaults to "#AA3333". :type increased_color: str, optional :param decreased_color: The color for the decrease. Defaults to "#3333AA". :type decreased_color: str, optional :param neutral_color: The color for the non-significant. Defaults to "#AAAAAA". :type neutral_color: str, optional :param significant_p_value_threshold: The threshold for the p value. Defaults to 0.05. :type significant_p_value_threshold: float, optional :param significant_log2_fold_change_threshold: The threshold for the log2 fold change. Defaults to 1.0. :type significant_log2_fold_change_threshold: float, optional :param annotate_significant: Whether to annotate the significant values. Defaults to True. :type annotate_significant: bool, optional :param annotate_neutral: Whether to annotate the neutral values. Defaults to False. :type annotate_neutral: bool, optional :param size_significant: The size of the significant points. Defaults to 20. :type size_significant: int, optional :param size_neutral: The size of the neutral points. Defaults to 20. :type size_neutral: int, optional :param fontsize: The font size for the annotations. Defaults to 8. :type fontsize: int, optional :param figsize: The size of the figure. Defaults to (10, 5). :type figsize: Tuple[Union[int, float], Union[int, float]], optional :param title: The title of the plot. Defaults to None. :type title: Optional[str], optional :returns: The figure. :rtype: plt.Figure