Description
Bug summary
An unhandled Done exception can occur in the wxagg backend. In the example below, the code can continue running, although some additional action is required to draw the figure as the plot is initially blank.
Code for reproduction
from matplotlib.backends.backend_wxagg import FigureFrameWxAgg
import matplotlib.figure as mfigure
import wx
def main():
app = wx.App()
figure = mfigure.Figure()
ax = figure.subplots()
ax.plot((0, 1))
frame = FigureFrameWxAgg(0, figure)
frame.Show()
figure.tight_layout() # triggers error in wxpython event handler
app.MainLoop()
if __name__ == '__main__':
main()
Actual outcome
Traceback (most recent call last):
File "C:\Python39-64\lib\site-packages\matplotlib\backends\backend_wx.py", line 653, in _onPaint
self.draw(drawDC=drawDC)
File "C:\Python39-64\lib\site-packages\matplotlib\backends\backend_wxagg.py", line 29, in draw
FigureCanvasAgg.draw(self)
File "C:\Python39-64\lib\site-packages\matplotlib\backends\backend_agg.py", line 436, in draw
self.figure.draw(self.renderer)
File "C:\Python39-64\lib\site-packages\matplotlib\backend_bases.py", line 1533, in _draw
def _draw(renderer): raise Done(renderer)
matplotlib.backend_bases._get_renderer..Done: <matplotlib.backends.backend_agg.RendererAgg object at 0x000002022EF5D250>
Expected outcome
The exception is caught somewhere or does not occur.
Additional information
I believe this only occurs in matplotlib version 3.5.0. This is with wxPython version 4.1.1.
It looks like figure.tight_layout() calls _get_renderer() which, in this example, subsequently calls _FigureCanvasWxBase.set_cursor(). Changing the self.Update() call in set_cursor() to self.Refresh() will allow the cbook._setattr_cm from _get_renderer() to exit prior to the paint event and avoid the exception. However, I'm not sure what the intended behavior is. Should a function call to get the renderer trigger a cursor change?
Operating system
Windows 10, 64-bit
Matplotlib Version
3.5.0
Matplotlib Backend
wxagg
Python version
3.9.9
Jupyter version
N/A
Installation
pip