You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: RangeSlider.set_val does not move the slider (only poly and value) #22706
When I call RangeSlider.set_val([0.0,0.1])
It changes only the blue poly object and the range value on the right side of the slider not the dot:
Code for reproduction
importnumpyasnpimportmatplotlib.pyplotaspltfrommatplotlib.widgetsimportRangeSlider# generate a fake imagenp.random.seed(19680801)
N=128img=np.random.randn(N, N)
fig, axs=plt.subplots(1, 2, figsize=(10, 5))
fig.subplots_adjust(bottom=0.25)
im=axs[0].imshow(img)
axs[1].hist(img.flatten(), bins='auto')
axs[1].set_title('Histogram of pixel intensities')
# Create the RangeSliderslider_ax=fig.add_axes([0.20, 0.1, 0.60, 0.03])
slider=RangeSlider(slider_ax, "Threshold", img.min(), img.max(),valinit=[0.0,1])
# Create the Vertical lines on the histogramlower_limit_line=axs[1].axvline(slider.val[0], color='k')
upper_limit_line=axs[1].axvline(slider.val[1], color='k')
defupdate(val):
# The val passed to a callback by the RangeSlider will# be a tuple of (min, max)# Update the image's colormapim.norm.vmin=val[0]
im.norm.vmax=val[1]
# Update the position of the vertical lineslower_limit_line.set_xdata([val[0], val[0]])
upper_limit_line.set_xdata([val[1], val[1]])
# Redraw the figure to ensure it updatesfig.canvas.draw_idle()
slider.set_val([0.0,5])
slider.on_changed(update)
plt.show()
Ahh actually there is yet another bug with the handles that I discovered looking at the code for this. For a vertical rangeslider the handle positions go bananas:
Activity
ianhi commentedon Mar 25, 2022
Ahh actually there is yet another bug with the handles that I discovered looking at the code for this. For a vertical rangeslider the handle positions go bananas:
This vertical bug, and the original bug both stem from the fact that the only updating of the slider handle position happens here:
matplotlib/lib/matplotlib/widgets.py
Lines 815 to 816 in 5971feb
set_valnext to where we update thepolynik1097 commentedon Mar 26, 2022
I will try recreating and fixing this issue to if that's okay @vpicouet @ianhi
vpicouet commentedon Mar 26, 2022
Yes!
andrew-fennell commentedon Mar 28, 2022
The PR #22711 will resolve the issues with both horizontal and vertical RangeSlider handle positions when using
set_val.QuLogic commentedon Mar 30, 2022
Fixed by #22711.