pandora.plotting module
- pandora.plotting.get_distinct_colors(n_colors: int) List[str][source]
Returns a list of n HSV colors evenly spaced in the HSV colorspace.
- Parameters:
- n_colorsint
Number of colors to return
- Returns:
- List[str]
List of n plotly HSV color strings.
- pandora.plotting.get_rdylgr_color_scale() List[Tuple[float, str]][source]
Returns a continuous hex color scale from red
(#d60000)to green(#209c05).- Returns:
- List[Tuple[float, str]]
A list of
(float, str)tuples that can be used as continuous color scale in plotly figures.
- pandora.plotting.improve_plotly_text_position(x_values: Series) List[str][source]
Returns improved text positions for sample annotations in plotly figures based on the x-values of the samples.
- Parameters:
- x_valuespd.Series
x values of the samples to plot
- Returns:
- List[str]
A list of text positions, one position for each sample in
x_values.
- pandora.plotting.plot_clusters(embedding: Embedding, dim_x: int = 0, dim_y: int = 1, kmeans_k: int | None = None, fig: Figure | None = None, **kwargs) Figure[source]
Plots the data for the provided Embedding data using the given dimension indices and color-codes samples according to their cluster label as inferred by using K-Means clustering.
- Parameters:
- embeddingEmbedding
Embedding data to plot.
- dim_xint
Index of the dimension plotted on the x-axis (zero-indexed).
- dim_yint
Index of the dimension plotted on the y-axis (zero-indexed).
- kmeans_kint
Optional k to use for K-Means clustering. If not set, the optimal number of clusters k is automatically determined based on the data provided by Embedding.
- figgo.Figure
Optional figure containing previous plotting data (e.g. another Embedding plot).
- **kwargs
Optional plot arguments passed to go.Scatter. Refer to the plotly documentation for options. The following settings are not allowed: [
x,y,mode,marker,marker_color,name]
- Returns:
- go.Figure
Plotly figure depicting the Embedding data.
- pandora.plotting.plot_embedding_comparison(embedding_comparison: EmbeddingComparison, dim_x: int = 0, dim_y: int = 1, **kwargs) Figure[source]
Method to plot the closest match between two Embeddings. Plots the transformed Embeddings based on the EmbeddingComparison object.
- Parameters:
- embedding_comparisonEmbeddingComparison
EmbeddingComparison object containing the two Embeddings to plot.
- dim_xint
Index of the dimension plotted on the x-axis (zero-indexed).
- dim_yint
Index of the dimension plotted on the y-axis (zero-indexed).
- **kwargs
Optional plot arguments passed to go.Scatter. Refer to the plotly documentation for options. The following settings are not allowed: [
x,y,mode,marker,marker_color,name,marker_symbol]
- Returns:
- go.Figure
Plotly figure depicting both Embeddings in
embedding_comparison.
- pandora.plotting.plot_embedding_comparison_rogue_samples(embedding_comparison: EmbeddingComparison, support_values: Series, support_value_rogue_cutoff: float = 0.5, dim_x: int = 0, dim_y: int = 1, **kwargs) Figure[source]
Method to plot the closest match between two Embeddings. Plots the transformed Embeddings based on the EmbeddingComparison object. Additionally, all samples with a support value below
support_value_rogue_cutoffare highlighted.- Parameters:
- embedding_comparisonEmbeddingComparison
EmbeddingComparison object containing the two Embeddings to plot.
- support_valuespd.Series
Pandora support values for all samples in the embedding data. The series’ indices should be the sample IDs and the values the respective support value.
- support_value_rogue_cutofffloat
Samples with a support value below this threshold are considered rogue and are highlighted by color, their sample ID and support value.
- dim_xint
Index of the dimension plotted on the x-axis (zero-indexed).
- dim_yint
Index of the dimension plotted on the y-axis (zero-indexed).
- **kwargs
Optional plot arguments passed to go.Scatter. Refer to the plotly documentation for options. The following settings are not allowed: [
x,y,mode,marker,marker_color,name, ` text`,textposition,marker_symbol]
- Returns:
- go.Figure
Plotly figure depicting both Embeddings in
embedding_comparisonand highlighting rouge samples.
- pandora.plotting.plot_populations(embedding: Embedding, dim_x: int = 0, dim_y: int = 1, fig: Figure | None = None, **kwargs) Figure[source]
Plots the data for the provided Embedding data using the given dimension indices and colors all populations as provided by Embedding using distinct colors.
- Parameters:
- embeddingEmbedding
Embedding data to plot.
- dim_xint
Index of the dimension plotted on the x-axis (zero-indexed).
- dim_yint
Index of the dimension plotted on the y-axis (zero-indexed).
- figgo.Figure, default=None
Optional figure containing previous plotting data (e.g. another Embedding plot).
- **kwargs
Optional plot arguments passed to go.Scatter. Refer to the plotly documentation for options. The following settings are not allowed: [
x,y,mode,marker,marker_color,name]
- Returns:
- go.Figure
Plotly figure depicting the Embedding data
- Raises:
- PandoraException
If there are no populations associated with the embedding data.
- pandora.plotting.plot_projections(embedding: Embedding, embedding_populations: Series, dim_x: int = 0, dim_y: int = 1, fig: Figure | None = None, **kwargs)[source]
Plots the data for the provided Embedding data using the given dimension indices. Only samples with populations not in embedding_populations are color-coded according to their population. All other samples are colored in lightgray.
Use this plotting function if you want to highlight only projected samples in an Embedding plot.
- Parameters:
- embeddingEmbedding
Embedding data to plot.
- embedding_populationspd.Series
Pandas Series of population names used to compute the Embedding. Samples belonging to these populations are plotted in lightgray.
- dim_xint
Index of the dimension plotted on the x-axis (zero-indexed).
- dim_yint
Index of the dimension plotted on the y-axis (zero-indexed).
- figgo.Figure
Optional figure containing previous plotting data (e.g. another Embedding plot).
- **kwargs
Optional plot arguments passed to go.Scatter. Refer to the plotly documentation for options. The following settings are not allowed: [
x,y,mode,marker,marker_color,name]
- Returns:
- go.Figure
Plotly figure depicting the Embedding data.
- Raises:
- PandoraException
If
embedding_populationsis empty. In this case there are not projected samples to plot.
- pandora.plotting.plot_support_values(embedding: Embedding, sample_support_values: Series, support_value_rogue_cutoff: float = 0.5, dim_x: int = 0, dim_y: int = 1, projected_samples: Series | None = None, **kwargs) Figure[source]
Plots the data for the provided Embedding data using the given dimension indices, color-coding the support value for each sample.
The colors range from red (low support) to green (high support). If projected_samples is set, only samples in projected_samples are color-coded according to their support value, all other samples are shown in lightgray.
- Parameters:
- embeddingEmbedding
Embedding data to plot.
- sample_support_valuespd.Series
Pandora support value for each sample in
embedding.embedding. Note: The index of the Series is expected to contain the sample IDs and to be identical toembedding.sample_ids.- support_value_rogue_cutofffloat
Samples with a support value below this threshold are annotated with the sample ID and the support value. All other samples are only color-coded.
- dim_xint
Index of the dimension plotted on the x-axis (zero-indexed).
- dim_yint
Index of the dimension plotted on the y-axis (zero-indexed).
- projected_samplespd.Series
Pandas series of sample IDs. If set, only samples in this list are color-coded according to their support value. All other samples are shown in gray.
- **kwargs
Optional plot arguments passed to go.Scatter. Refer to the plotly documentation for options. The following settings are not allowed: [
x,y,mode,marker,marker_color,name,text,textposition]
- Returns:
- go.Figure
Plotly figure depicting the Embedding data.
- Raises:
- PandoraException
If no samples are left to plot after filtering samples present in both embedding data and
sample_support_values.
- Warns:
- UserWarning
If not all samples in
sample_support_valuesare present in the embedding data. This is most likely due to outlier detection during the computation of the embedding.If not all samples in the embedding data have a support value associated.