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

Commit9067a2d

Browse files
committed
Don't allow bins lower than 0 if dtype is unisgned
1 parentd589d5f commit9067a2d

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

‎examples/histogram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
importnapari
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

Lines 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=0ifnp.issubdtype(layer_data.dtype,np.integer)else2
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=0ifis_unsignedelse-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
defdraw(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=intifnp.issubdtype(data.dtype,np.integer)elsefloat,
177+
dtype=data.dtype,
173178
)
174179

175180
iflayer.rgb:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp