[Matplotlib-devel] Catching parsing errors in Mathtext

Raymond Osborn rayosborn at mac.com
Mon Oct 11 20:16:06 EDT 2021


When testing v3.5.0rc1, I had a fright when my plots suddenly disappeared while attempting to change their title with ax.set_title. It turned out that this occurred because of a typo in the title text; I had closed a brace with a parenthesis by mistake. However, I was puzzled why this hadn’t triggered an exception. In the debugger, it looks as if this is because the exception was caught when calling draw_idle, but was never reraised because context managers stopped it. For some reason, errors do get raised when I run Pyplot in IPython with the same typo, but I haven’t worked out yet why embedding Matplotlib stops them appearing. Instead, the plot just disappears when I click on the PyQt canvas.

The point of this post is too ask whether it might not be better to call the pyparsing module earlier in this process so that the user is immediately alerted to the invalid text rather than waiting for an attempted redraw. I don’t know enough about the text rendering engine to know whether there are reasons this is not possible, so I thought I would ask the question. Shouldn’t any call to set_title, set_xlabel, etc, immediately warn the user that the text doesn’t parse? If this is an efficiency issue, couldn’t the parsing result be cached in the Text object?

With regards,
Ray Osborn




More information about the Matplotlib-devel mailing list