Skip to content

Commit 233336f

Browse files
authored
Merge pull request #48 from BiAPoL/unify_properties
Unify properties
2 parents bea4f7e + da39b00 commit 233336f

File tree

9 files changed

+669
-957
lines changed

9 files changed

+669
-957
lines changed

docs/artists_api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
~Histogram2D.visible
112112
~Histogram2D.color_indices
113113
~Histogram2D.bins
114+
~Histogram2D.cmin
114115
~Histogram2D.histogram
115116
~Histogram2D.histogram_colormap
116117
~Histogram2D.histogram_interpolation
@@ -148,6 +149,7 @@
148149
.. autoattribute:: visible
149150
.. autoattribute:: color_indices
150151
.. autoattribute:: bins
152+
.. autoattribute:: cmin
151153
.. autoattribute:: histogram
152154
.. autoattribute:: histogram_colormap
153155
.. autoattribute:: histogram_interpolation

docs/examples/histogram_artist_example.ipynb

Lines changed: 153 additions & 110 deletions
Large diffs are not rendered by default.

docs/examples/scatter_artist_example.ipynb

Lines changed: 55 additions & 31 deletions
Large diffs are not rendered by default.

docs/plotter_api.md

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212
~CanvasWidget.active_artist
1313
~CanvasWidget.active_selector
1414
15-
.. rubric:: Attributes Summary
16-
17-
.. autosummary::
18-
19-
~CanvasWidget.selection_tools_layout
20-
~CanvasWidget.selection_toolbar
21-
~CanvasWidget.class_spinbox
22-
~CanvasWidget.artists
23-
~CanvasWidget.selectors
24-
2515
.. rubric:: Methods Summary
2616
2717
.. autosummary::
@@ -45,14 +35,6 @@
4535
.. autoattribute:: active_artist
4636
.. autoattribute:: active_selector
4737
48-
.. rubric:: Attributes Documentation
49-
50-
.. autoattribute:: selection_tools_layout
51-
.. autoattribute:: selection_toolbar
52-
.. autoattribute:: class_spinbox
53-
.. autoattribute:: artists
54-
.. autoattribute:: selectors
55-
5638
.. rubric:: Methods Documentation
5739
5840
.. automethod:: add_artist

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ install_requires =
3838
qtpy
3939
napari-matplotlib
4040
nap-plot-tools>=0.1.0
41+
numpy>=1.22.0
4142

4243
python_requires = >=3.9
4344
include_package_data = True

src/biaplotter/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.1.0"
1+
__version__ = "0.2.0"
22
from .artists import Histogram2D, Scatter
33
from .colormap import BiaColormap
44
from .plotter import CanvasWidget

src/biaplotter/_tests/test_artists.py

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def on_color_indices_changed(color_indices):
5050
assert scatter.color_indices.shape == (size,)
5151

5252
# Test scatter colors
53-
colors = scatter._scatter.get_facecolors()
53+
colors = scatter._mpl_artists['scatter'].get_facecolors()
5454
assert np.all(colors[0] == scatter.overlay_colormap(0))
5555
assert np.all(colors[50] == scatter.overlay_colormap(2))
5656

@@ -69,27 +69,27 @@ def on_color_indices_changed(color_indices):
6969
# Test size property
7070
scatter.size = 5.0
7171
assert scatter.size == 5.0
72-
sizes = scatter._scatter.get_sizes()
72+
sizes = scatter._mpl_artists['scatter'].get_sizes()
7373
assert np.all(sizes == 5.0)
7474

7575
scatter.size = np.linspace(1, 10, size)
7676
assert np.all(scatter.size == np.linspace(1, 10, size))
77-
sizes = scatter._scatter.get_sizes()
77+
sizes = scatter._mpl_artists['scatter'].get_sizes()
7878
assert np.all(sizes == np.linspace(1, 10, size))
7979

8080
# Test size reset when new data is set
8181
scatter.data = np.random.rand(size // 2, 2)
8282
assert np.all(scatter.size == 50.0) # that's the default
83-
sizes = scatter._scatter.get_sizes()
83+
sizes = scatter._mpl_artists['scatter'].get_sizes()
8484
assert np.all(sizes == 50.0)
8585

8686
# test alpha
8787
scatter.alpha = 0.5
88-
assert np.all(scatter._scatter.get_alpha() == 0.5)
88+
assert np.all(scatter._mpl_artists['scatter'].get_alpha() == 0.5)
8989

9090
# test alpha reset when new data is set
9191
scatter.data = np.random.rand(size, 2)
92-
assert np.all(scatter._scatter.get_alpha() == 1.0)
92+
assert np.all(scatter._mpl_artists['scatter'].get_alpha() == 1.0)
9393

9494
# Test changing overlay_colormap
9595
assert scatter.overlay_colormap.name == "cat10_modified"
@@ -98,7 +98,7 @@ def on_color_indices_changed(color_indices):
9898

9999
# Test scatter color indices after continuous overlay_colormap
100100
scatter.color_indices = np.linspace(0, 1, size)
101-
colors = scatter._scatter.get_facecolors()
101+
colors = scatter._mpl_artists['scatter'].get_facecolors()
102102
assert np.all(colors[0] == plt.cm.viridis(0))
103103

104104
# Test scatter color_normalization_method
@@ -181,7 +181,7 @@ def on_color_indices_changed(color_indices):
181181
assert histogram.cmin == 0
182182

183183
# Test overlay colors
184-
overlay_array = histogram._overlay_histogram_image.get_array()
184+
overlay_array = histogram._mpl_artists['overlay_histogram_image'].get_array()
185185
assert overlay_array.shape == (bins, bins, 4)
186186
# indices where overlay_array is not zero
187187
indices = np.where(overlay_array[..., -1] != 0)
@@ -229,7 +229,7 @@ def on_color_indices_changed(color_indices):
229229

230230
# Don't draw overlay histogram if color_indices are nan
231231
histogram.color_indices = np.nan
232-
assert histogram._overlay_histogram_image is None
232+
assert 'overlay_histogram_image' not in histogram._mpl_artists.keys()
233233

234234

235235
# Test calculate_statistic_histogram_method for different statistics
@@ -245,43 +245,3 @@ def on_color_indices_changed(color_indices):
245245
[[0.0, np.nan, np.nan], [np.nan, 3.0, np.nan], [np.nan, np.nan, 7.5]]
246246
),
247247
]
248-
249-
250-
@pytest.mark.parametrize(
251-
"statistic,expected_array",
252-
zip(statistics, expected_results),
253-
ids=statistics,
254-
)
255-
def test_calculate_statistic_histogram_method(statistic, expected_array):
256-
input_xy_data = np.array(
257-
[
258-
[1, 2],
259-
[3, 4],
260-
[3, 5],
261-
[4, 5],
262-
[5, 6],
263-
[6, 7],
264-
]
265-
)
266-
bins = 3
267-
input_features = np.array([0, 1, 2, 6, 7, 8])
268-
269-
expected_histogram_array = np.array(
270-
[[1.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 2.0]]
271-
)
272-
273-
histogram = Histogram2D(data=input_xy_data, bins=bins)
274-
histogram_array, x_edges, y_edges = histogram.histogram
275-
assert np.all(histogram_array == expected_histogram_array)
276-
# Get the bin index for each x value ( -1 to start from index 0 and clip to handle edge cases)
277-
x_bin_indices = (
278-
np.digitize(input_xy_data[:, 0], x_edges, right=False) - 1
279-
).clip(0, len(x_edges) - 2)
280-
# Get the bin index for each y value ( -1 to start from index 0 and clip to handle edge cases)
281-
y_bin_indices = (
282-
np.digitize(input_xy_data[:, 1], y_edges, right=False) - 1
283-
).clip(0, len(y_edges) - 2)
284-
result = histogram._calculate_statistic_histogram(
285-
x_bin_indices, y_bin_indices, input_features, statistic=statistic
286-
)
287-
assert np.array_equal(result, expected_array, equal_nan=True)

0 commit comments

Comments
 (0)