Skip to content

Commit 784fedc

Browse files
committed
Add show_results parameter to Plotter methods for geometry/table result display
1 parent 7310ae7 commit 784fedc

1 file changed

Lines changed: 70 additions & 49 deletions

File tree

datalab_kernel/plotter.py

Lines changed: 70 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ def plot(
498498
obj_or_name: DataObject | str,
499499
title: str | None = None,
500500
show_roi: bool = True,
501+
show_results: bool = True,
501502
**kwargs,
502503
) -> PlotResult:
503504
"""Plot an object or retrieve and plot by name.
@@ -506,6 +507,7 @@ def plot(
506507
obj_or_name: Object to plot, or name of object in workspace
507508
title: Optional plot title override
508509
show_roi: Whether to show ROIs defined in the object
510+
show_results: Whether to show geometry/table results from metadata
509511
**kwargs: Additional plotting options
510512
511513
Returns:
@@ -523,7 +525,9 @@ def plot(
523525
if title is None and hasattr(obj, "title"):
524526
title = obj.title
525527

526-
return PlotResult(obj, title=title, show_roi=show_roi, **kwargs)
528+
return PlotResult(
529+
obj, title=title, show_roi=show_roi, show_results=show_results, **kwargs
530+
)
527531

528532
def plot_signals(
529533
self,
@@ -534,6 +538,7 @@ def plot_signals(
534538
xunit: str | None = None,
535539
yunit: str | None = None,
536540
show_roi: bool = True,
541+
show_results: bool = True,
537542
**kwargs,
538543
) -> MultiSignalPlotResult:
539544
"""Plot multiple signals on a single plot.
@@ -547,6 +552,7 @@ def plot_signals(
547552
xunit: Unit for the x-axis
548553
yunit: Unit for the y-axis
549554
show_roi: Whether to show ROIs defined in SignalObj instances
555+
show_results: Whether to show geometry/table results from metadata
550556
**kwargs: Additional plotting options
551557
552558
Returns:
@@ -567,6 +573,7 @@ def plot_signals(
567573
xunit=xunit,
568574
yunit=yunit,
569575
show_roi=show_roi,
576+
show_results=show_results,
570577
**kwargs,
571578
)
572579

@@ -582,6 +589,7 @@ def plot_images(
582589
yunit: str | None = None,
583590
zunit: str | None = None,
584591
show_roi: bool = True,
592+
show_results: bool = True,
585593
results: list | None = None,
586594
**kwargs,
587595
) -> MultiImagePlotResult:
@@ -599,6 +607,7 @@ def plot_images(
599607
yunit: Unit for the y-axis
600608
zunit: Unit for the colorbar
601609
show_roi: Whether to show ROIs defined in ImageObj instances
610+
show_results: Whether to show geometry/table results from metadata
602611
results: Optional list of GeometryResult objects to overlay
603612
**kwargs: Additional plotting options (e.g., colormap)
604613
@@ -623,6 +632,7 @@ def plot_images(
623632
yunit=yunit,
624633
zunit=zunit,
625634
show_roi=show_roi,
635+
show_results=show_results,
626636
results=results,
627637
**kwargs,
628638
)
@@ -681,6 +691,7 @@ def __init__(
681691
obj: DataObject,
682692
title: str | None = None,
683693
show_roi: bool = True,
694+
show_results: bool = True,
684695
results: list | None = None,
685696
**kwargs,
686697
) -> None:
@@ -690,12 +701,14 @@ def __init__(
690701
obj: Object to display
691702
title: Plot title
692703
show_roi: Whether to show ROIs
704+
show_results: Whether to show geometry/table results from metadata
693705
results: Optional list of GeometryResult objects to overlay (for images)
694706
**kwargs: Additional options
695707
"""
696708
self._obj = obj
697709
self._title = title
698710
self._show_roi = show_roi
711+
self._show_results = show_results
699712
self._results = results
700713
self._kwargs = kwargs
701714

@@ -802,14 +815,14 @@ def _render_signal(self, ax: Axes) -> None:
802815
for roi in obj.roi:
803816
_add_single_roi_to_axes(ax, roi, obj)
804817

805-
# Auto-extract and display geometry results from object metadata
806-
metadata_results = _extract_geometry_results_from_metadata(obj)
807-
for result in metadata_results:
808-
_add_geometry_to_axes(ax, result)
818+
# Auto-extract and display geometry/table results from object metadata
819+
if self._show_results:
820+
metadata_results = _extract_geometry_results_from_metadata(obj)
821+
for result in metadata_results:
822+
_add_geometry_to_axes(ax, result)
809823

810-
# Auto-extract and display table results (statistics) from metadata
811-
table_results = _extract_table_results_from_metadata(obj)
812-
_add_table_results_to_axes(ax, table_results, metadata_results)
824+
table_results = _extract_table_results_from_metadata(obj)
825+
_add_table_results_to_axes(ax, table_results, metadata_results)
813826

814827
def _render_image(self, ax: Axes, fig) -> None:
815828
"""Render image data to axes.
@@ -868,26 +881,27 @@ def _render_image(self, ax: Axes, fig) -> None:
868881
for roi in obj.roi:
869882
_add_single_roi_to_axes(ax, roi, obj)
870883

871-
# Overlay geometry results from explicit parameter or from metadata
872-
results_to_display = []
873-
if self._results is not None:
874-
result_list = (
875-
self._results
876-
if isinstance(self._results, (list, tuple))
877-
else [self._results]
878-
)
879-
results_to_display.extend(result_list)
884+
# Overlay geometry/table results (explicit or from metadata)
885+
if self._show_results:
886+
results_to_display = []
887+
if self._results is not None:
888+
result_list = (
889+
self._results
890+
if isinstance(self._results, (list, tuple))
891+
else [self._results]
892+
)
893+
results_to_display.extend(result_list)
880894

881-
# Auto-extract geometry results from object metadata
882-
metadata_results = _extract_geometry_results_from_metadata(obj)
883-
results_to_display.extend(metadata_results)
895+
# Auto-extract geometry results from object metadata
896+
metadata_results = _extract_geometry_results_from_metadata(obj)
897+
results_to_display.extend(metadata_results)
884898

885-
for result in results_to_display:
886-
_add_geometry_to_axes(ax, result)
899+
for result in results_to_display:
900+
_add_geometry_to_axes(ax, result)
887901

888-
# Auto-extract and display table results (statistics) from metadata
889-
table_results = _extract_table_results_from_metadata(obj)
890-
_add_table_results_to_axes(ax, table_results, results_to_display)
902+
# Auto-extract and display table results (statistics) from metadata
903+
table_results = _extract_table_results_from_metadata(obj)
904+
_add_table_results_to_axes(ax, table_results, results_to_display)
891905

892906
def __repr__(self) -> str:
893907
"""Return string representation."""
@@ -913,6 +927,7 @@ def __init__(
913927
xunit: str | None = None,
914928
yunit: str | None = None,
915929
show_roi: bool = True,
930+
show_results: bool = True,
916931
**kwargs,
917932
) -> None:
918933
"""Initialize multi-signal plot result.
@@ -925,6 +940,7 @@ def __init__(
925940
xunit: Unit for the x-axis
926941
yunit: Unit for the y-axis
927942
show_roi: Whether to show ROIs
943+
show_results: Whether to show geometry/table results from metadata
928944
**kwargs: Additional options
929945
"""
930946
self._objs = objs
@@ -934,6 +950,7 @@ def __init__(
934950
self._xunit = xunit
935951
self._yunit = yunit
936952
self._show_roi = show_roi
953+
self._show_results = show_results
937954
self._kwargs = kwargs
938955

939956
def _repr_html_(self) -> str:
@@ -1007,14 +1024,14 @@ def _render_to_png(self) -> bytes:
10071024
else None,
10081025
)
10091026

1010-
# Auto-extract and display geometry results from object metadata
1011-
metadata_results = _extract_geometry_results_from_metadata(obj)
1012-
for result in metadata_results:
1013-
_add_geometry_to_axes(ax, result)
1027+
# Auto-extract and display geometry/table results from metadata
1028+
if self._show_results:
1029+
metadata_results = _extract_geometry_results_from_metadata(obj)
1030+
for result in metadata_results:
1031+
_add_geometry_to_axes(ax, result)
10141032

1015-
# Auto-extract and display table results (statistics) from metadata
1016-
table_results = _extract_table_results_from_metadata(obj)
1017-
_add_table_results_to_axes(ax, table_results, metadata_results)
1033+
table_results = _extract_table_results_from_metadata(obj)
1034+
_add_table_results_to_axes(ax, table_results, metadata_results)
10181035

10191036
elif isinstance(data_or_obj, tuple) and len(data_or_obj) == 2:
10201037
# Tuple of (x, y) arrays
@@ -1083,6 +1100,7 @@ def __init__(
10831100
yunit: str | None = None,
10841101
zunit: str | None = None,
10851102
show_roi: bool = True,
1103+
show_results: bool = True,
10861104
results: list | None = None,
10871105
rows: int | None = None,
10881106
share_axes: bool = True,
@@ -1101,6 +1119,7 @@ def __init__(
11011119
yunit: Unit for the y-axis
11021120
zunit: Unit for the colorbar
11031121
show_roi: Whether to show ROIs
1122+
show_results: Whether to show geometry/table results from metadata
11041123
results: Optional list of GeometryResult objects to overlay
11051124
rows: Fixed number of rows in the grid, or None to compute automatically
11061125
share_axes: Whether to share axes across plots
@@ -1116,6 +1135,7 @@ def __init__(
11161135
self._yunit = yunit
11171136
self._zunit = zunit
11181137
self._show_roi = show_roi
1138+
self._show_results = show_results
11191139
self._results = results
11201140
self._rows = rows
11211141
self._share_axes = share_axes
@@ -1273,26 +1293,27 @@ def _render_to_png(self) -> bytes:
12731293
for roi in img.roi:
12741294
_add_single_roi_to_axes(ax, roi, img)
12751295

1276-
# Collect geometry results: explicit + from metadata
1277-
results_to_display = []
1278-
if result is not None:
1279-
result_list_item = (
1280-
result if isinstance(result, (list, tuple)) else [result]
1281-
)
1282-
results_to_display.extend(result_list_item)
1296+
# Collect and display geometry/table results if enabled
1297+
if self._show_results:
1298+
results_to_display = []
1299+
if result is not None:
1300+
result_list_item = (
1301+
result if isinstance(result, (list, tuple)) else [result]
1302+
)
1303+
results_to_display.extend(result_list_item)
12831304

1284-
# Auto-extract geometry results from object metadata
1285-
if is_image_obj:
1286-
metadata_results = _extract_geometry_results_from_metadata(img)
1287-
results_to_display.extend(metadata_results)
1305+
# Auto-extract geometry results from object metadata
1306+
if is_image_obj:
1307+
metadata_results = _extract_geometry_results_from_metadata(img)
1308+
results_to_display.extend(metadata_results)
12881309

1289-
for res in results_to_display:
1290-
_add_geometry_to_axes(ax, res)
1310+
for res in results_to_display:
1311+
_add_geometry_to_axes(ax, res)
12911312

1292-
# Auto-extract and display table results (statistics) from metadata
1293-
if is_image_obj:
1294-
table_results = _extract_table_results_from_metadata(img)
1295-
_add_table_results_to_axes(ax, table_results, results_to_display)
1313+
# Auto-extract and display table results (statistics) from metadata
1314+
if is_image_obj:
1315+
table_results = _extract_table_results_from_metadata(img)
1316+
_add_table_results_to_axes(ax, table_results, results_to_display)
12961317

12971318
# Hide unused subplots
12981319
for idx in range(n_images, len(axes_flat)):

0 commit comments

Comments
 (0)