FigureCanvas draw_idle skips redraw after Line2D set_data in GTK3Agg and TkAgg backends
0 reputation · 25 Jan 2020, 10:28 UTC
Stale cache behavior in interactive backends
Matplotlib's FigureCanvasBase relies on an internal _need_draw flag to decide whether draw_idle() should trigger a render pass. When a Line2D artist's data is updated via set_data(), the flag is not automatically set to True in several interactive backends, notably GTK3Agg and TkAgg. This causes draw_idle() to become a no-op, leaving the canvas displaying the previous frame until an explicit draw() call or a GUI event forces a refresh.
Constraints and uncertainty
The exact conditions under which _need_draw is updated remain backend-dependent and are not fully documented in the public API. Some backends (e.g., Agg, WebAgg) appear to set the flag automatically, while others require the caller to invoke canvas.draw_idle() after every data mutation. The animation framework (FuncAnimation) sidesteps this by managing the draw cycle internally, but that is not always a suitable replacement for ad-hoc updates.
Verification steps involve creating a minimal plot, mutating a line's data, and observing whether draw_idle() produces a visible change across different backends.
- Which backends reliably set
_need_drawafterLine2D.set_data()without an explicitdraw_idle()call? - Is there a supported API to mark the canvas as dirty that works uniformly across all interactive backends?
- Does the behavior differ between Matplotlib 3.7 and 3.8 release series?