Skip to content

Navigation Menu

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

Appearance settings

Commit 9067a2d

Browse filesBrowse files
committed
Don't allow bins lower than 0 if dtype is unisgned
1 parent d589d5f commit 9067a2d
Copy full SHA for 9067a2d

File tree

2 files changed

+14
-9
lines changed
Filter options

2 files changed

+14
-9
lines changed

‎examples/histogram.py

Copy file name to clipboardExpand all lines: examples/histogram.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import napari
66

77
viewer = napari.Viewer()
8-
viewer.open_sample("napari", "kidney")
8+
viewer.open_sample("napari", "coins")
99

1010
viewer.window.add_plugin_dock_widget(
1111
plugin_name="napari-matplotlib", widget_name="Histogram"

‎src/napari_matplotlib/histogram.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/histogram.py
+13-8Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(
4646
bins_start.setStepType(QAbstractSpinBox.AdaptiveDecimalStepType)
4747
bins_start.setRange(-1e10, 1e10)
4848
bins_start.setValue(0)
49-
bins_start.setWrapping(True)
49+
bins_start.setWrapping(False)
5050
bins_start.setKeyboardTracking(False)
5151
bins_start.setDecimals(2)
5252

@@ -55,6 +55,7 @@ def __init__(
5555
bins_stop.setStepType(QAbstractSpinBox.AdaptiveDecimalStepType)
5656
bins_stop.setRange(-1e10, 1e10)
5757
bins_stop.setValue(100)
58+
bins_start.setWrapping(False)
5859
bins_stop.setKeyboardTracking(False)
5960
bins_stop.setDecimals(2)
6061

@@ -148,13 +149,17 @@ def on_update_layers(self) -> None:
148149
self.autoset_widget_bins(data=layer_data)
149150

150151
# Only allow integer bins for integer data
152+
# And only allow values greater than 0 for unsigned integers
151153
n_decimals = 0 if np.issubdtype(layer_data.dtype, np.integer) else 2
152-
self.findChild(QDoubleSpinBox, name="bins start").setDecimals(
153-
n_decimals
154-
)
155-
self.findChild(QDoubleSpinBox, name="bins stop").setDecimals(
156-
n_decimals
157-
)
154+
is_unsigned = layer_data.dtype.kind == "u"
155+
minimum_value = 0 if is_unsigned else -1e10
156+
157+
bins_start = self.findChild(QDoubleSpinBox, name="bins start")
158+
bins_stop = self.findChild(QDoubleSpinBox, name="bins stop")
159+
bins_start.setDecimals(n_decimals)
160+
bins_stop.setDecimals(n_decimals)
161+
bins_start.setMinimum(minimum_value)
162+
bins_stop.setMinimum(minimum_value)
158163

159164
def draw(self) -> None:
160165
"""
@@ -169,7 +174,7 @@ def draw(self) -> None:
169174
self.bins_start,
170175
self.bins_stop,
171176
self.bins_num,
172-
dtype=int if np.issubdtype(data.dtype, np.integer) else float,
177+
dtype=data.dtype,
173178
)
174179

175180
if layer.rgb:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.