troutpy.pl.point_metric_comparison

troutpy.pl.point_metric_comparison#

troutpy.pl.point_metric_comparison(sdata, points_key='transcripts', x_col='cosine_similarity', y_col='cosine_sim_stainings', hue_col='enrichment_class', gene_key='gene', gene_list=None, subsample_fraction=None, table_key='table', structure_table_key='structure_table', source_table_key='source_score', palette_name='30colors', continuous_palette='viridis', s=2.0, alpha=0.3, figsize=(7, 6), title=None, show_consensus=True, seed=42)#

Plot a joint scatter/KDE comparison of two point-level metrics, colored by a third variable.

Builds a seaborn.JointGrid comparing x_col and y_col from sdata[points_key], colored or grouped by hue_col. Any of x_col, y_col, or hue_col not already present in the points table is looked up from sdata[source_table_key], sdata[structure_table_key], or sdata[table_key] (in that order) via structure_id/cell_id mappings.

Parameters:
  • sdata (SpatialData) – SpatialData object containing the points element and the tables referenced by table_key, structure_table_key, and source_table_key.

  • points_key (str (default: 'transcripts')) – Key of the points element in sdata.

  • x_col (str (default: 'cosine_similarity')) – Column to plot on the x-axis.

  • y_col (str (default: 'cosine_sim_stainings')) – Column to plot on the y-axis.

  • hue_col (str (default: 'enrichment_class')) – Column used to color/group points. If numeric, points are colored on a continuous scale; otherwise treated as categorical.

  • gene_key (str (default: 'gene')) – Column in the points table containing gene names.

  • gene_list (Optional[list[str]] (default: None)) – If provided, restrict the plot to points of these genes.

  • subsample_fraction (Optional[float] (default: None)) – If provided and less than 1, randomly subsample the points to this fraction before plotting.

  • table_key (str (default: 'table')) – Key of the cell-level table in sdata, used as a fallback source for x_col/y_col/hue_col.

  • structure_table_key (str (default: 'structure_table')) – Key of the segmentation-free structure table in sdata, used as a fallback source for x_col/y_col/hue_col via structure_id.

  • source_table_key (str (default: 'source_score')) – Key of the source-score table in sdata, used as a fallback source for x_col/y_col/hue_col.

  • palette_name (str (default: '30colors')) – Palette for categorical hue_col values, resolved via troutpy.pl.get_palette(), or colormap name for numeric hue_col.

  • continuous_palette (str (default: 'viridis')) – Fallback continuous colormap used when palette_name is not a valid matplotlib colormap and hue_col is numeric.

  • s (float (default: 2.0)) – Marker size for the scatter plot.

  • alpha (float (default: 0.3)) – Transparency of the scatter points.

  • figsize (tuple[float, float] (default: (7, 6))) – Size of the figure.

  • title (Optional[str] (default: None)) – Custom title for the plot. If None, a title is generated from x_col, y_col, and hue_col.

  • show_consensus (bool (default: True)) – If True and both axes range over roughly [0, 1], draw a diagonal consensus (y = x) reference line.

  • seed (int (default: 42)) – Random seed used for subsampling, if subsample_fraction is set.

Return type:

JointGrid

Returns:

The joint grid containing the plot.