Plot numpy datetime64 with matplotlib

前端 未结 3 1082
暗喜
暗喜 2020-12-03 05:17

I have two numpy arrays 1D, one is time of measurement in datetime64 format, for example:

array([2011-11-15 01:08:11, 2011-11-16 02:08:04, ..., 2012-07-0         


        
相关标签:
3条回答
  • 2020-12-03 05:22

    Matplotlib>=2.2 natively supports plotting datetime64 arrays. See https://github.com/matplotlib/matplotlib/blob/master/doc/users/prev_whats_new/whats_new_2.2.rst#support-for-numpydatetime64:

    Matplotlib has supported datetime.datetime dates for a long time in matplotlib.dates. We now support numpy.datetime64 dates as well. Anywhere that dateime.datetime could be used, numpy.datetime64 can be used. eg:

    time = np.arange('2005-02-01', '2005-02-02', dtype='datetime64[h]')
    plt.plot(time)
    
    0 讨论(0)
  • 2020-12-03 05:23

    You might want to try this:

    plot_date(timeSeries, data)
    

    By default, the x axis will be considered a date axis, and y a regular one. This can be customized.

    0 讨论(0)
  • 2020-12-03 05:46
    from datetime import datetime
    a=np.datetime64('2002-06-28').astype(datetime)
    plot_date(a,2)
    
    0 讨论(0)
提交回复
热议问题