Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit adaa8e5

Browse files
authored
Merge pull request #11000 from jklymak/fix-repr-text
FIX: improve Text repr to not error if non-float x and y.
2 parents 4966c3f + 0089509 commit adaa8e5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,10 @@ def test_text_as_text_opacity():
496496
plt.text(0.25, 0.5, '50% using `alpha`', alpha=0.5)
497497
plt.text(0.25, 0.75, '50% using `alpha` and 100% `color`', alpha=0.5,
498498
color=(0, 0, 0, 1))
499+
500+
501+
def test_text_repr():
502+
# smoketest to make sure text repr doesn't error for category
503+
plt.plot(['A', 'B'], [1, 2])
504+
txt = plt.text(['A'], 0.5, 'Boo')
505+
print(txt)

lib/matplotlib/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class Text(Artist):
132132
_cached = cbook.maxdict(50)
133133

134134
def __repr__(self):
135-
return "Text(%g,%g,%s)" % (self._x, self._y, repr(self._text))
135+
return "Text(%s, %s, %s)" % (self._x, self._y, repr(self._text))
136136

137137
def __init__(self,
138138
x=0, y=0, text='',

0 commit comments

Comments
 (0)