lisbet.plotting#

Plotting utilities for LISBET.

This module provides a variety of functions for visualizing data and analysis results related to the LISBET project. The functions cover a range of tasks, including plotting UMAP embeddings, F1 score matrices, transition graphs, silhouette profiles, and dendrograms.

Functions

get_custom_cmap(n[, palette, alpha, desat])

Generate a custom colormap with n colors.

mm2inch(x)

Convert millimeters to inches.

plot_dendrogram(linkage_matrix, ...)

Plots a dendrogram for hierarchical clustering with clusters colored according to labels.

plot_embedding_summary(embeddings, labels, ...)

Plots a summary of embeddings over time, including expert and predicted labels.

plot_f1_matrix(f1_matrix[, xlabels, ylabels, ax])

Plot an F1 score matrix as a heatmap.

plot_group_points(data, y, test_dict, ax)

Plots group-wise boxplots and strip plots with statistical test results.

plot_heatmap(distance, link_matrix, ...)

Plots a heatmap of the sorted distance matrix along with cluster and prototype information.

plot_points(data, y, ax)

Plots boxplots and strip plots for the given data based on Motif ID.

plot_slh_profile(distance, link_matrix, ...)

Plots the silhouette score profile for hierarchical clustering.

plot_slh_score(all_n_clusters, all_score, ...)

Plots the silhouette score as a function of the number of clusters.

plot_transition_graph(trans_prob[, ...])

Plots a transition graph based on the provided transition probability matrix.

plot_umap2d(data, labels[, targets, ...])

Plot a 2D UMAP embedding with class labels.

pval2star(pval)

Convert a p-value to the corresponding star notation (APA style).

lisbet.plotting.mm2inch(x)[source]#

Convert millimeters to inches.

Parameters:

x (float or array-like) – The value(s) in millimeters to convert.

Returns:

The converted value(s) in inches.

Return type:

float or array-like

lisbet.plotting.pval2star(pval)[source]#

Convert a p-value to the corresponding star notation (APA style).

Parameters:

pval (float) – The p-value to convert.

Returns:

The corresponding star notation, where “*” indicates p less than or equal to 0.001, “” indicates p less than or equal to 0.01, “*” indicates p less than or equal to 0.05, and “ns” indicates p greater than 0.05.

Return type:

str

lisbet.plotting.get_custom_cmap(n, palette='Set2', alpha=None, desat=None)[source]#

Generate a custom colormap with n colors.

Parameters:
  • n (int) – Number of colors in the colormap.

  • palette (str) – A valid seaborn/matplotlib palette. Default is “Set2”.

  • alpha (list, optional) – Alpha values for each color in the colormap. If None, no alpha values are applied. Default is None.

Returns:

cmap – A listed colormap with n colors.

Return type:

matplotlib.colors.ListedColormap

lisbet.plotting.plot_umap2d(data, labels, targets=None, sample_size=None, seed=None, marker_size='auto', cmap=None, cbar_loc='top', cbar_label='Motif ID', cbar_ticklabels=None, ax=None)[source]#

Plot a 2D UMAP embedding with class labels.

Parameters:
  • data (array-like, shape (n_samples, 2)) – The 2D coordinates of the points to plot.

  • labels (array-like, shape (n_samples,)) – The class labels for each point.

  • sample_size (int, optional) – The number of points to randomly sample for plotting. If None, all points are plotted. Default is None.

  • seed (int, optional) – Random seed for reproducibility when sampling. Default is None.

  • cmap (matplotlib.colors.Colormap, optional) – Colormap for coloring the points. If None, a custom colormap is generated. Default is None.

  • cbar_loc (str, optional) – Location of the colorbar. Can be “top” or “right”. Default is “top”.

  • cbar_label (str, optional) – Label for the colorbar. Default is “Motif ID”.

  • cbar_ticklabels (list, optional) – Custom tick labels for the colorbar. If None, labels are based on the unique class labels. Default is None.

  • ax (matplotlib.axes.Axes, optional) – Axes object to draw the plot onto. If None, a new figure and axes are created. Default is None.

Return type:

None

lisbet.plotting.plot_f1_matrix(f1_matrix, xlabels=None, ylabels=None, ax=None)[source]#

Plot an F1 score matrix as a heatmap.

Parameters:
  • f1_matrix (array-like, shape (n_classes, n_classes)) – The F1 score matrix.

  • xlabels (list, optional) – Labels for the x-axis. If None, indices are used. Default is None.

  • ylabels (list, optional) – Labels for the y-axis. If None, indices are used. Default is None.

  • ax (matplotlib.axes.Axes, optional) – Axes object to draw the plot onto. If None, a new figure and axes are created. Default is None.

Returns:

The plot is drawn on the provided or created axes.

Return type:

None

lisbet.plotting.plot_transition_graph(trans_prob, node_sizes=150, edge_vmin=None, edge_vmax=None, cmap=None, ax=None)[source]#

Plots a transition graph based on the provided transition probability matrix.

Parameters:
  • trans_prob (numpy.ndarray) – A square matrix where element [i, j] represents the probability of transitioning from state i to state j.

  • node_sizes (int or list, optional) – The size of the nodes in the graph. If an int, all nodes will have the same size.

  • edge_vmin (float, optional) – Minimum value for the edge colormap normalization.

  • edge_vmax (float, optional) – Maximum value for the edge colormap normalization.

  • cmap (matplotlib.colors.Colormap, optional) – Colormap for the edges of the graph.

  • ax (matplotlib.axes.Axes, optional) – Axes object to draw the plot onto, otherwise uses the current axes.

Returns:

  • nodes (matplotlib.collections.PathCollection) – The drawn nodes of the graph.

  • labels (dict) – The labels of the nodes in the graph.

  • cbar (matplotlib.colorbar.Colorbar) – Colorbar corresponding to the edge weights.

lisbet.plotting.plot_points(data, y, ax)[source]#

Plots boxplots and strip plots for the given data based on Motif ID.

Parameters:
  • data (pandas.DataFrame) – The data containing ‘Motif ID’ and the variable to plot on the y-axis.

  • y (str) – The name of the column in data to be plotted on the y-axis.

  • ax (matplotlib.axes.Axes) – Axes object to draw the plot onto.

Return type:

None

lisbet.plotting.plot_group_points(data, y, test_dict, ax)[source]#

Plots group-wise boxplots and strip plots with statistical test results.

Parameters:
  • data (pandas.DataFrame) – The data containing ‘Motif ID’, ‘Group label’, and the variable to plot on the y-axis.

  • y (str) – The name of the column in data to be plotted on the y-axis.

  • test_dict (dict) – A dictionary where keys are Motif IDs and values are statistical test results (e.g., t-test results).

  • ax (matplotlib.axes.Axes) – Axes object to draw the plot onto.

Return type:

None

lisbet.plotting.plot_embedding_summary(embeddings, labels, predictions, fps=None, cmap_human=None, cmap_machine=None, axarr=None)[source]#

Plots a summary of embeddings over time, including expert and predicted labels.

Parameters:
  • embeddings (numpy.ndarray) – The embedding matrix where each row corresponds to a time point.

  • labels (numpy.ndarray) – Array of expert-provided labels corresponding to the embeddings.

  • predictions (numpy.ndarray) – Array of model-predicted labels corresponding to the embeddings.

  • axarr (numpy.ndarray of matplotlib.axes.Axes, optional) – Array of Axes objects to draw the plots onto. If not provided, new subplots will be created.

Return type:

None

lisbet.plotting.plot_slh_score(all_n_clusters, all_score, best_n_clusters, best_score, ax)[source]#

Plots the silhouette score as a function of the number of clusters.

Parameters:
  • all_n_clusters (list or numpy.ndarray) – A list of different numbers of clusters.

  • all_score (list or numpy.ndarray) – Corresponding silhouette scores for each number of clusters.

  • best_n_clusters (int) – The number of clusters with the best silhouette score.

  • best_score (float) – The best silhouette score obtained.

  • ax (matplotlib.axes.Axes) – Axes object to draw the plot onto.

Return type:

None

lisbet.plotting.plot_slh_profile(distance, link_matrix, cluster_labels, ax)[source]#

Plots the silhouette score profile for hierarchical clustering.

Parameters:
  • distance (numpy.ndarray) – Precomputed distance matrix.

  • link_matrix (numpy.ndarray) – Linkage matrix obtained from hierarchical clustering.

  • cluster_labels (numpy.ndarray) – Cluster labels for each sample.

  • ax (matplotlib.axes.Axes) – Axes object to draw the plot onto.

Return type:

None

lisbet.plotting.plot_heatmap(distance, link_matrix, cluster_labels, prototypes, ax)[source]#

Plots a heatmap of the sorted distance matrix along with cluster and prototype information.

Parameters:
  • distance (numpy.ndarray) – Precomputed distance matrix.

  • link_matrix (numpy.ndarray) – Linkage matrix obtained from hierarchical clustering.

  • cluster_labels (numpy.ndarray) – Cluster labels for each sample.

  • prototypes (numpy.ndarray) – Array of prototype indices corresponding to each cluster.

  • ax (matplotlib.axes.Axes) – Axes object to draw the plot onto.

Return type:

None

lisbet.plotting.plot_dendrogram(linkage_matrix, cluster_labels, ax)[source]#

Plots a dendrogram for hierarchical clustering with clusters colored according to labels.

Parameters:
  • linkage_matrix (numpy.ndarray) – Linkage matrix obtained from hierarchical clustering.

  • cluster_labels (numpy.ndarray) – Cluster labels for each sample.

  • ax (matplotlib.axes.Axes) – Axes object to draw the plot onto.

Return type:

None