Elffuss BraidHub

kikocis/auto-code-rover public

main · 1.7 KiBRawPermalink
1[Bug]: using clf and pyplot.draw in range slider on_changed callback blocks input to widgets
2### Bug summary
3
4When using clear figure, adding new widgets and then redrawing the current figure in the on_changed callback of a range slider the inputs to all the widgets in the figure are blocked. When doing the same in the button callback on_clicked, everything works fine.
5
6### Code for reproduction
7
8```python
9import matplotlib.pyplot as pyplot
10import matplotlib.widgets as widgets
11
12def onchanged(values):
13 print("on changed")
14 print(values)
15 pyplot.clf()
16 addElements()
17 pyplot.draw()
18
19def onclick(e):
20 print("on click")
21 pyplot.clf()
22 addElements()
23 pyplot.draw()
24
25def addElements():
26 ax = pyplot.axes([0.1, 0.45, 0.8, 0.1])
27 global slider
28 slider = widgets.RangeSlider(ax, "Test", valmin=1, valmax=10, valinit=(1, 10))
29 slider.on_changed(onchanged)
30 ax = pyplot.axes([0.1, 0.30, 0.8, 0.1])
31 global button
32 button = widgets.Button(ax, "Test")
33 button.on_clicked(onclick)
34
35addElements()
36
37pyplot.show()
38```
39
40
41### Actual outcome
42
43The widgets can't receive any input from a mouse click, when redrawing in the on_changed callback of a range Slider.
44When using a button, there is no problem.
45
46### Expected outcome
47
48The range slider callback on_changed behaves the same as the button callback on_clicked.
49
50### Additional information
51
52The problem also occurred on Manjaro with:
53- Python version: 3.10.9
54- Matplotlib version: 3.6.2
55- Matplotlib backend: QtAgg
56- Installation of matplotlib via Linux package manager
57
58
59### Operating system
60
61Windows 10
62
63### Matplotlib Version
64
653.6.2
66
67### Matplotlib Backend
68
69TkAgg
70
71### Python version
72
733.11.0
74
75### Jupyter version
76
77_No response_
78
79### Installation
80
81pip