Skip to content

Histogram of list of datetimes #11899

Closed
@Zinjaai

Description

@Zinjaai

Bug report

Bug summary
When creating a histogram of a list of datetimes, the input seems to be interpreted as a sequency of arrays.

Code for reproduction

from datetime import datetime
from matplotlib import pyplot as plt
plt.hist([datetime(2018,1,1),  datetime(2018, 2, 1),  datetime(2018,3, 1)])

# We get the expected result,  when we cast the list to a numpy array (but only if we specify the dtype?!)
# import numpy
# plt.hist(numpy.array([datetime(2018,1,1),  datetime(2018, 2, 1),  datetime(2018,3, 1)], dtype='datetime64[h]'))

Actual outcome

Output of n is a list of arrays, indicating that the input dates are interpreted as a sequence of arrays.

# If applicable, paste the console output here
([array([1., 0., 0., 0., 0., 0., 0., 0., 0., 0.]),
  array([0., 0., 0., 0., 0., 1., 0., 0., 0., 0.]),   #  <---  expected array instead of list of arrays
  array([0., 0., 0., 0., 0., 0., 0., 0., 0., 1.])],
 array([736695. , 736700.9, 736706.8, 736712.7, 736718.6, 736724.5,
        736730.4, 736736.3, 736742.2, 736748.1, 736754. ]),
 <a list of 3 Lists of Patches objects>)

Output of matplotlib version 2.2.0, 2.2.2 and 2.2.3

Expected outcome

# If applicable, paste the console output here
(array([1., 0., 0., 0., 0., 1., 0., 0., 0., 1.]),
 array([736695. , 736700.9, 736706.8, 736712.7, 736718.6, 736724.5,
        736730.4, 736736.3, 736742.2, 736748.1, 736754. ]),
 <a list of 10 Patch objects>)

This worked in matplotlib version 2.1.2

Matplotlib version

  • Operating system: Fedora 27
  • Matplotlib version: 2.2.3
  • Matplotlib backend (print(matplotlib.get_backend())): agg
  • Python version: 3.6.5
  • Jupyter version (if applicable):
  • Other libraries:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions