Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
text() doesn't validate its x, y coordinates except at draw time, which mean that calling e.g. ax.text() with invalid coordinates in an interactive shell will brick the figure.
Code for reproduction
In [1]:classT:"""just a placeholder"""In [2]:plt.text(T(),T(),"foo")Out[2]:Text(<__main__.Tobjectat0x7f4af7d8fb80>,<__main__.Tobjectat0x7f4af7d8ff70>,'foo')Traceback (mostrecentcalllast):<elided>File"/home/antony/src/extern/matplotlib/lib/matplotlib/text.py",line830,inget_unitless_positionx=float(self.convert_xunits(self._x))TypeError:float()argumentmustbeastringoranumber,not'T'
and future plots will also trigger the same exception, unless you realized you can remove the Text with something likeax.texts[-1].remove()
.
Actual outcome
See above.
Expected outcome
Validation when the Text() is constructed.
Note, though that the inputs are not necessarily float(-like): it can be any scalar supported by the units machinery (well, technically, it should match the unit of the axes if that's already set, but at instantiation time the Text doesn't know what Axes it's going to be attached to (it could even end up being a Figure-level text) so let's not get ahead of ourselves).
Operating system
No response
Matplotlib Version
3.4.2.post1804+gb600026fe8
Matplotlib Backend
any
Python version
3.9
Jupyter version
No response
Other libraries
No response
Installation
No response
Conda channel
No response