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

Skip to content

Unicode issue in matplotlib.dates #7630

Closed
@djkirkham

Description

@djkirkham

The import of __future__.unicode_literals in matplotlib.dates causes an error when calling datetime.datetime.tzname() on a datetime created with tzinfo=matplotlib.dates.UTC:

>>> import matplotlib.dates
>>> import datetime
>>> dt = datetime.datetime(2000,1,1, tzinfo=matplotlib.dates.UTC)
>>> dt.tzname()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: tzinfo.tzname() must return None or a string, not 'unicode'

This causes issues when plotting with a date formatter:

>>> import matplotlib.pyplot as plt
>>> import matplotlib.dates
>>> plt.plot([700000], [0])
[<matplotlib.lines.Line2D object at 0x7fe41dbb4050>]
>>> plt.gca().xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%Z'))
>>> plt.show()
...
  File .../lib/python2.7/site-packages/matplotlib/dates.py", line 589, in strftime
    return cbook.unicode_safe(dt.strftime(fmt))
TypeError: tzinfo.tzname() must return None or a string, not 'unicode'

(I've omitted most of the call stack)

Matplotlib 1.5.3, Python 2.7.12, Linux
Installed from source
The issue doesn't exist in Matplotlib 1.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions