GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — [Bug]: Slider.set_val renders the figure before it notifies its observers, sometimes causing two renders per event · Issue #32526 · matplotlib/matplotlib Open DescriptionBug summary
Code for reproductionimport matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt from matplotlib.widgets import Slider fig, (ax, axsl) = plt.subplots(2, 1, height_ratios=[4, 1], figsize=(4, 3)) fig.subplots_adjust(bottom=0.25) (line,) = ax.plot([0, 1], [0, 0]) # an artist the callback will update sl = Slider(axsl, "x", 0.0, 1.0, valinit=0.0) ndraw = [0] _real_draw_idle = fig.canvas.draw_idle def counting_draw_idle(*a, **k): ndraw[0] += 1 return _real_draw_idle(*a, **k) fig.canvas.draw_idle = counting_draw_idle at_callback = [] def on_change(v): at_callback.append(ndraw[0]) # how many draws already happened line.set_ydata([v, v]) fig.canvas.draw_idle() # the callback's own draw sl.on_changed(on_change) for drawon in (True, False): sl.drawon = drawon ndraw[0] = 0 at_callback.clear() sl.set_val(0.7) print(f"drawon={drawon!s:<5} draws before the callback ran: {at_callback[0]}" f" draws in total: {ndraw[0]}") Actual outcomedrawon=True draws before the callback ran: 1 draws in total: 2 Expected outcomeOne render per event, none of them before the observers run. Either set_val notifies first and draws afterwards, or it leaves drawing to the observers, in which case the docstring should say that callbacks are responsible for the draw_idle. Additional informationThe widget draws in The doubled render halves the interactive frame rate of any app built this way, and on a slower backend the stale frame is visible. In the app that prompted this report (four panels redrawn per slider event) one event cost 97 ms, 49 ms of it the wasted render; this was really obvious interactively.
This was discovered by a DeepSeek v4.1 Flash agent running on Openmath OS, but I verified it independently. Operating systemDebian Matplotlib Version3.10.1+dfsg1 Matplotlib Backendqtagg (or Agg as in the MWE) Python versionPython 3.13.5 Jupyter versionN/A InstallationLinux package manager Activity
MetadataMetadataAssigneesTypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |