Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6513a69

Browse files
committed
Re-use histogram binning
1 parent06d4b17 commit6513a69

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

‎src/napari_matplotlib/histogram.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
_COLORS= {"r":"tab:red","g":"tab:green","b":"tab:blue"}
2121

2222

23+
def_get_bins(data:npt.NDArray[Any])->npt.NDArray[Any]:
24+
ifdata.dtype.kindin {"i","u"}:
25+
# Make sure integer data types have integer sized bins
26+
step=np.ceil(np.ptp(data)/100)
27+
returnnp.arange(np.min(data),np.max(data)+step,step)
28+
else:
29+
# For other data types, just have 128 evenly spaced bins
30+
returnnp.linspace(np.min(data),np.max(data),100)
31+
32+
2333
classHistogramWidget(SingleAxesWidget):
2434
"""
2535
Display a histogram of the currently selected layer.
@@ -70,13 +80,7 @@ def draw(self) -> None:
7080

7181
# Important to calculate bins after slicing 3D data, to avoid reading
7282
# whole cube into memory.
73-
ifdata.dtype.kindin {"i","u"}:
74-
# Make sure integer data types have integer sized bins
75-
step=abs(np.max(data)-np.min(data))//100
76-
step=max(1,step)
77-
bins=np.arange(np.min(data),np.max(data)+step,step)
78-
else:
79-
bins=np.linspace(np.min(data),np.max(data),100)
83+
bins=_get_bins(data)
8084

8185
iflayer.rgb:
8286
# Histogram RGB channels independently
@@ -215,9 +219,9 @@ def draw(self) -> None:
215219
ifdataisNone:
216220
return
217221

218-
_,bins,patches=self.axes.hist(
219-
data,bins=50,edgecolor="white",linewidth=0.3
220-
)
222+
bins=_get_bins(data)
223+
224+
_,bins,patches=self.axes.hist(data,bins=bins.tolist())
221225
patches=cast(BarContainer,patches)
222226

223227
# recolor the histogram plot
Loading
Loading

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp