matplotlib日期格式从UTC毫秒

时间:2017-11-26 23:08:21

标签: datetime matplotlib datetime-format

我有外汇货币的报价数据,我试图用matplotlib绘制。

我可以绘制数据,但x轴上的日期以毫秒为单位,但没有帮助。

我已设法将日期转换为日期时间格式,但结果如下:

datetime.datetime(2015, 12, 12, 2, 0)

当我尝试运行我的代码时,我收到以下错误:

line 804, in _candlestick
xy=(t - OFFSET, lower),
TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'float'

Process finished with exit code 1

我的代码基本上如下:

quotes = [dates, open, highest, low, close, volume]

ax = plt.subplot2grid((6, 4), (1, 0), rowspan=6, colspan=4, facecolor='#FFFFFF')

ax.xaxis.set_major_formatter(mdates.DateFormatter('%y-%m-%d %H:%M:%S'))

MOCHLV = zip(quotes[0], quotes[1], quotes[2], quotes[3], quotes[4], quotes[5])


matplotlib.finance.candlestick_ohlc(ax, MOCHLV, width=1.9, colorup='#53c156', colordown='#ff1717')

plt.ylabel('BTC/USD')
plt.xlabel('Date Hours:Minutes')
plt.show()

0 个答案:

没有答案