Skip to content

Commit b0c8de2

Browse files
authored
Fix setting contrast limits when the histogram widget is open (#309)
* Pass a list to line.set_xdata rather than a float * Add test for changing contrast limits with histogram open * Update changelog
1 parent 64edb23 commit b0c8de2

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

docs/changelog.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
Changelog
22
=========
33

4-
2.1.0
4+
3.0.1
5+
-----
6+
Bug fixes
7+
~~~~~~~~~
8+
- Fix an error that happened when changing the contrast limit when the histogram widget was open
9+
10+
3.0.0
511
-----
612
New features
713
~~~~~~~~~~~~

src/napari_matplotlib/histogram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def _update_contrast_lims(self) -> None:
115115
for lim, line in zip(
116116
self.layers[0].contrast_limits, self._contrast_lines, strict=False
117117
):
118-
line.set_xdata(lim)
118+
line.set_xdata([lim])
119119

120120
self.figure.canvas.draw()
121121

src/napari_matplotlib/tests/test_histogram.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,15 @@ def test_change_layer(make_napari_viewer, brain_data, astronaut_data):
152152
viewer.layers.selection.clear()
153153
viewer.layers.selection.add(viewer.layers[1])
154154
assert_figures_not_equal(widget.figure, fig1)
155+
156+
157+
def test_change_contrast(make_napari_viewer, astronaut_data):
158+
viewer = make_napari_viewer()
159+
viewer.add_image(astronaut_data[0], **astronaut_data[1])
160+
161+
widget = HistogramWidget(viewer)
162+
viewer.window.add_dock_widget(widget)
163+
164+
# update contrast limits of image layer, and check no errors are thrown
165+
image_layer = viewer.layers[0]
166+
image_layer.contrast_limits = [2, 50]

0 commit comments

Comments
 (0)