Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Description
Bug report
hist2d
interprets dates differently than doplot
,scatter,
etc. In the example, manually applyingdate2num
before callinghist2d
makes the output work as expected, but is not necessary forplot
.
Code for reproduction
importmatplotlibimportnumpyasnpimportmatplotlib.pyplotaspltprint(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 controlax[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 hist2dax[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 firsthist2d
plot (upper right), unlike O(10^5) in the x-limits.
Expected outcome
hist2d
should interpret time as withplot
.
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)