Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: Invalid text coordinates brick figure #20911

Open
@anntzer

Description

@anntzer

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp