From 88b68a67ce2557f9cada50d7acdd6a2b4d117132 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sun, 8 Apr 2018 13:25:43 -0700 Subject: [PATCH 1/2] FIX: improve Text repr to not error if non-float x and y. --- lib/matplotlib/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index d2df6c6e392e..148cf25035bd 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -132,7 +132,7 @@ class Text(Artist): _cached = cbook.maxdict(50) def __repr__(self): - return "Text(%g,%g,%s)" % (self._x, self._y, repr(self._text)) + return "Text(%s, %s, %s)" % (self._x, self._y, repr(self._text)) def __init__(self, x=0, y=0, text='', From 0089509b61ea14333e5bac0aa94c06d288f633c2 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sun, 8 Apr 2018 13:32:50 -0700 Subject: [PATCH 2/2] TST: test repr for category x --- lib/matplotlib/tests/test_text.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index 4d22075b7dd5..04013d3550f2 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -496,3 +496,10 @@ def test_text_as_text_opacity(): plt.text(0.25, 0.5, '50% using `alpha`', alpha=0.5) plt.text(0.25, 0.75, '50% using `alpha` and 100% `color`', alpha=0.5, color=(0, 0, 0, 1)) + + +def test_text_repr(): + # smoketest to make sure text repr doesn't error for category + plt.plot(['A', 'B'], [1, 2]) + txt = plt.text(['A'], 0.5, 'Boo') + print(txt)