0

In matplotlib, one of the axes may be of datetime values. The following example, for instance, works well:

import datetime as dt
import matplotlib.patches as patches
circle = patches.Circle(xy=(dt.datetime.now(), 1), radius=5)

But this fails:

cp = patches.CirclePolygon(xy=(dt.datetime.now(), 1), radius=5, resolution=10)

with this error:

Traceback (most recent call last):
  File "testcpol.py", line 14, in <module>
    p = patches.CirclePolygon(xy=(x, y), radius=5, resolution=10)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/patches.py", line 1349, in __init__
    **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/patches.py", line 797, in __init__
    self._update_transform()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/patches.py", line 805, in _update_transform
    .translate(*self.xy)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/transforms.py", line 1945, in translate
    np.float_)
TypeError: float() argument must be a string or a number

Seems like CirclePolygon tries to convert the datetime into a float for some reason. Any idea why, or how to bypass it?

Bach
  • 6,145
  • 7
  • 36
  • 61
  • This seems to be the issue for other patches as well -- such as `RegularPolygon`. – Bach Mar 27 '16 at 20:00
  • Perhaps related: http://stackoverflow.com/questions/31162780/how-to-plot-a-rectangle-on-a-datetime-axis-using-matplotlib – Bach Dec 28 '16 at 12:13

0 Answers0