Skip to content

Commit ec8eabf

Browse files
committed
Move data getting
1 parent f2d8995 commit ec8eabf

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

src/napari_matplotlib/features.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
from typing import Dict, List, Optional
1+
from typing import Any, Dict, List, Optional, Tuple
22

33
import napari
44
import napari.layers
5+
import numpy as np
6+
import numpy.typing as npt
7+
import pandas as pd
58
from qtpy.QtWidgets import QComboBox, QLabel, QVBoxLayout
69

710
from napari_matplotlib.base import NapariMPLWidget
@@ -86,6 +89,27 @@ def _ready_to_plot(self) -> bool:
8689
and all([self.get_key(dim) in valid_keys for dim in self.dims])
8790
)
8891

92+
def _get_data_names(
93+
self,
94+
) -> Tuple[List[npt.NDArray[Any]], List[str]]:
95+
"""
96+
Get the plot data from the ``features`` attribute of the first
97+
selected layer.
98+
99+
Returns
100+
-------
101+
data : List[np.ndarray]
102+
List contains X and Y columns from the FeatureTable. Returns
103+
an empty array if nothing to plot.
104+
names : List[str]
105+
Names for each axis.
106+
"""
107+
feature_table: pd.DataFrame = self.layers[0].features
108+
109+
names = [str(self.get_key(dim)) for dim in self.dims]
110+
data = [np.array(feature_table[key]) for key in names]
111+
return data, names
112+
89113
def on_update_layers(self) -> None:
90114
"""
91115
Called when the layer selection changes by ``self.update_layers()``.

src/napari_matplotlib/scatter.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,28 +122,5 @@ def draw(self) -> None:
122122
super().draw()
123123

124124
def _get_data(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
125-
"""
126-
Get the plot data from the ``features`` attribute of the first
127-
selected layer.
128-
129-
Returns
130-
-------
131-
data : List[np.ndarray]
132-
List contains X and Y columns from the FeatureTable. Returns
133-
an empty array if nothing to plot.
134-
x_axis_name : str
135-
The title to display on the x axis. Returns
136-
an empty string if nothing to plot.
137-
y_axis_name: str
138-
The title to display on the y axis. Returns
139-
an empty string if nothing to plot.
140-
"""
141-
feature_table = self.layers[0].features
142-
143-
x = feature_table[self.get_key("x")]
144-
y = feature_table[self.get_key("y")]
145-
146-
x_axis_name = str(self.get_key("x"))
147-
y_axis_name = str(self.get_key("y"))
148-
149-
return x, y, x_axis_name, y_axis_name
125+
data, names = self._get_data_names()
126+
return data[0], data[1], names[0], names[1]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy