@@ -435,29 +435,34 @@ def test_plot_can_color_labels_by_gene_symbols(self, sdata_blobs: SpatialData):
435435 "blobs_labels" , color = "GeneA" , table_name = "table" , gene_symbols = "gene_symbol"
436436 ).pl .show ()
437437
438- def test_plot_can_render_labels_as_points (self , sdata_blobs : SpatialData ):
439- """as_points draws one colored dot per label at its centroid instead of the mask."""
440- sdata_blobs .pl .render_labels ("blobs_labels" , color = "instance_id" , as_points = True , size = 100 ).pl .show ()
438+ @staticmethod
439+ def _as_points (sdata_blobs : SpatialData , method : str , color : str = "instance_id" ):
440+ # identical params for both backends, so the matplotlib and datashader baselines are comparable
441+ return sdata_blobs .pl .render_labels ("blobs_labels" , color = color , as_points = True , method = method , size = 600 )
441442
442- def test_plot_labels_as_points_respects_size (self , sdata_blobs : SpatialData ):
443- """size sets the scatter marker area; larger size -> larger dots."""
444- sdata_blobs .pl .render_labels ("blobs_labels" , color = "instance_id" , as_points = True , size = 600 ).pl .show ()
445-
446- def test_plot_labels_as_points_datashader (self , sdata_blobs : SpatialData ):
447- """as_points with method='datashader' rasterizes the colored centroids instead of drawing markers."""
448- sdata_blobs .pl .render_labels (
449- "blobs_labels" , color = "instance_id" , as_points = True , method = "datashader" , size = 600
450- ).pl .show ()
451-
452- def test_plot_labels_as_points_datashader_categorical (self , sdata_blobs : SpatialData ):
453- """Categorical-coloured as_points centroids datashade with a legend (color_source_vector path)."""
443+ @staticmethod
444+ def _add_categorical_color (sdata_blobs : SpatialData ) -> str :
454445 max_col = sdata_blobs ["table" ].to_df ().idxmax (axis = 1 )
455446 sdata_blobs ["table" ].obs ["which_max" ] = pd .Categorical (
456447 max_col , categories = sdata_blobs ["table" ].to_df ().columns , ordered = True
457448 )
458- sdata_blobs .pl .render_labels (
459- "blobs_labels" , color = "which_max" , as_points = True , method = "datashader" , size = 600
460- ).pl .show ()
449+ return "which_max"
450+
451+ def test_plot_labels_as_points_matplotlib (self , sdata_blobs : SpatialData ):
452+ """as_points draws one colored dot per label at its centroid (matplotlib backend)."""
453+ self ._as_points (sdata_blobs , "matplotlib" ).pl .show ()
454+
455+ def test_plot_labels_as_points_datashader (self , sdata_blobs : SpatialData ):
456+ """Same render via datashader; should look maximally similar to the matplotlib baseline."""
457+ self ._as_points (sdata_blobs , "datashader" ).pl .show ()
458+
459+ def test_plot_labels_as_points_categorical_matplotlib (self , sdata_blobs : SpatialData ):
460+ """Categorical-coloured as_points with a legend (matplotlib backend)."""
461+ self ._as_points (sdata_blobs , "matplotlib" , color = self ._add_categorical_color (sdata_blobs )).pl .show ()
462+
463+ def test_plot_labels_as_points_categorical_datashader (self , sdata_blobs : SpatialData ):
464+ """Same categorical render via datashader (color_source_vector + legend path)."""
465+ self ._as_points (sdata_blobs , "datashader" , color = self ._add_categorical_color (sdata_blobs )).pl .show ()
461466
462467
463468def test_raises_when_table_does_not_annotate_element (sdata_blobs : SpatialData ):
0 commit comments