Skip to content

Generalise functionality for plotting from feature tables #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Start a features mixin class
  • Loading branch information
dstansby committed Jun 15, 2023
commit dba5a00b3dbf4138d9daaa91df28668ac9a7a3a5
21 changes: 21 additions & 0 deletions src/napari_matplotlib/features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import napari.layers

from napari_matplotlib.base import NapariMPLWidget
from napari_matplotlib.util import Interval


class FeaturesMixin(NapariMPLWidget):
"""
Mixin to help with widgets that plot data from a features table stored
on a single layer.
"""

n_layers_input = Interval(1, 1)
# All layers that have a .features attributes
input_layer_types = (
napari.layers.Labels,
napari.layers.Points,
napari.layers.Shapes,
napari.layers.Tracks,
napari.layers.Vectors,
)
13 changes: 2 additions & 11 deletions src/napari_matplotlib/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from qtpy.QtWidgets import QComboBox, QLabel, QVBoxLayout, QWidget

from .base import SingleAxesWidget
from .features import FeaturesMixin
from .util import Interval

__all__ = ["ScatterBaseWidget", "ScatterWidget", "FeaturesScatterWidget"]
Expand Down Expand Up @@ -85,21 +86,11 @@ def _get_data(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
return x, y, x_axis_name, y_axis_name


class FeaturesScatterWidget(ScatterBaseWidget):
class FeaturesScatterWidget(ScatterBaseWidget, FeaturesMixin):
"""
Widget to scatter data stored in two layer feature attributes.
"""

n_layers_input = Interval(1, 1)
# All layers that have a .features attributes
input_layer_types = (
napari.layers.Labels,
napari.layers.Points,
napari.layers.Shapes,
napari.layers.Tracks,
napari.layers.Vectors,
)

def __init__(
self,
napari_viewer: napari.viewer.Viewer,
Expand Down