Bug report
hist2d interprets dates differently than do plot, scatter, etc. In the example, manually applying date2num before calling hist2d makes the output work as expected, but is not necessary for plot.
Code for reproduction
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
print(matplotlib.__version__)
t = np.array(['2020-04-02T23:00:00.749079563', '2020-04-02T23:00:00.749083039',
'2020-04-02T23:00:01.792519894', '2020-04-02T23:00:01.793246307',
'2020-04-02T23:00:01.793248355', '2020-04-02T23:00:01.795347666',
'2020-04-02T23:00:01.796964828', '2020-04-02T23:00:01.798717183',
'2020-04-02T23:00:01.800349212', '2020-04-02T23:00:01.801143192'],
dtype='datetime64[ns]')
tlim = np.array(['2020-04-02T23:00:00', '2020-04-02T23:00:02'],
dtype='datetime64[ns]')
z = np.arange(t.shape[0], dtype=float)
fig, ax = plt.subplots(3,2, figsize=(12,12))
# plot with no axis control
ax[0,0].plot(t, z, '.')
ax[0,1].hist2d(t, z, bins=[5, 5])
# set axes to expected range with default time handling
# plot works, hist2d doesnt.
ax[1,0].plot(t, z, '.')
ax[1,0].set_xlim(tlim[0], tlim[1])
ax[1,1].hist2d(t, z, bins=[5, 5])
ax[1,1].plot(t, z, '.')
ax[1,1].set_xlim(tlim[0], tlim[1])
# manually converting dates fixes hist2d
ax[2,0].plot(t, z, '.')
ax[2,0].set_xlim(tlim[0], tlim[1])
ax[2,1].hist2d(matplotlib.dates.date2num(t), z, bins=[5, 5])
ax[2,1].plot(t, z, '.')
ax[2,1].set_xlim(tlim[0], tlim[1])
Actual outcome
(737517.9583333334, 737517.9583564815) # output of set_xlim call

Note that the times are O(10^18) in the first hist2d plot (upper right), unlike O(10^5) in the x-limits.
Expected outcome
hist2d should interpret time as with plot.
Matplotlib version
- Operating system: MacOS Catalina
- Matplotlib version: 3.2.1 (conda-forge)
- Matplotlib backend (
print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline
- Python version: 3.6.7
- Jupyter version (if applicable): 6.1.3 (client)
Bug report
hist2dinterprets dates differently than doplot,scatter,etc. In the example, manually applyingdate2numbefore callinghist2dmakes the output work as expected, but is not necessary forplot.Code for reproduction
Actual outcome
Note that the times are O(10^18) in the first
hist2dplot (upper right), unlike O(10^5) in the x-limits.Expected outcome
hist2dshould interpret time as withplot.Matplotlib version
print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline