8000 [Bug]: using clf and pyplot.draw in range slider on_changed callback blocks input to widgets · Issue #25345 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Bug]: using clf and pyplot.draw in range slider on_changed callback blocks input to widgets #25345
Closed
@pinna9001

Description

@pinna9001

Bug summary

When 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.

Code for reproduction

import matplotlib.pyplot as pyplot
import matplotlib.widgets as widgets

def onchanged(values):
    print("on changed")
    print(values)
    pyplot.clf()
    addElements()
    pyplot.draw()

def onclick(e):
    print("on click")
    pyplot.clf()
    addElements()
    pyplot.draw()

def addElements():
    ax = pyplot.axes([0.1, 0.45, 0.8, 0.1])
    global slider
    slider = widgets.RangeSlider(ax, "Test", valmin=1, valmax=10, valinit=(1, 10))
    slider.on_changed(onchanged)
    ax = pyplot.axes([0.1, 0.30, 0.8, 0.1])
    global button
    button = widgets.Button(ax, "Test")
    button.on_clicked(onclick)

addElements()

pyplot.show()

Actual outcome

The widgets can't receive any input from a mouse click, when redrawing in the on_changed callback of a range Slider.
When using a button, there is no problem.

Expected outcome

The range slider callback on_changed behaves the same as the button callback on_clicked.

Additional information

The problem also occurred on Manjaro with:

  • Python version: 3.10.9
  • Matplotlib version: 3.6.2
  • Matplotlib backend: QtAgg
  • Installation of matplotlib via Linux package manager

Operating system

Windows 10

Matplotlib Version

3.6.2

Matplotlib Backend

TkAgg

Python version

3.11.0

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0