我正在尝试制作一个水平条形图,其中条形表示后续的时间间隔。到目前为止,这是我的方法:
import matplotlib.pyplot as plt
import numpy as np
date1 = np.datetime64('2014-12-31')
date2 = np.datetime64('2014-10-30')
fig = plt.figure( figsize=(12,8) )
ax1 = fig.add_subplot( 111 )
# make horizontal bar plot
ax1.barh( 1., width=(date1-date2), height=.3, left=date1, align='center' )
plt.show()
不过,Matplotlib 不喜欢这样。这是我收到的错误消息:
TypeError: ufunc add cannot use operands with types dtype('float64') and dtype('<m8[D]')
听起来 matplotlib 对用作条形宽度的时间间隔不满意。任何提示如何让 matplotlib 再次快乐?
我正在使用numpy 1.15.1和 matplotlib 2.2.3。
相关分类