Skip to content

FIX: improve Text repr to not error if non-float x and y. #11000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2018

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Apr 8, 2018

PR Summary

closes #10996

The __repr__ of Text assumed that txt._x and txt_y are floats, but they are unitized data, and hence not necessarily floats.

import matplotlib.pyplot as plt
from datetime import datetime

plt.plot([datetime(year=2016,month=4,day=1),datetime(year=2016,month=8,day=1)],[0,4])
tx=plt.text(datetime(year=2016,month=6,day=1), 1, "1", color="black", fontsize=12)
print(tx)
plt.show()

Before:

Traceback (most recent call last):
  File "testTextRep.py", line 8, in <module>
    print(tx)
  File "/Users/jklymak/matplotlib/lib/matplotlib/text.py", line 135, in __repr__
    return "Text(%g,%g,%s)" % (self._x, self._y, repr(self._text))
TypeError: must be real number, not datetime.datetime

Now:

Text(2016-06-01 00:00:00, 1, '1')

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant

@tacaswell tacaswell added this to the v3.0 milestone Apr 9, 2018
@tacaswell tacaswell merged commit adaa8e5 into matplotlib:master Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plotting text with datetime axis causes warning
3 participants