python-3.x - 使用烛台_ohlc 为时间戳使用 date2num 的正确方法是什么
问题描述
我的数据看起来像这样(Date
, Open
, High
, Low
, Close
):
ohlc = [
[1502929058, 1.2652, 1.2653, 1.265, 1.2653],
[1502929059, 1.267, 1.267, 1.267, 1.267],
[1502929060, 1.2655, 1.2656, 1.2655, 1.2656],
[1502929061, 1.2652, 1.2653, 1.2652, 1.2653],
[1502929062, 1.2631, 1.2631, 1.263, 1.2631],
[1502929063, 1.2625, 1.2625, 1.2625, 1.2625],
[1502929064, 1.2619, 1.2619, 1.2619, 1.2619],
[1502929065, 1.2622, 1.2623, 1.2622, 1.2623],
[1502929066, 1.2622, 1.2623, 1.2622, 1.2623],
[1502929067, 1.2617, 1.262, 1.2617, 1.262]
]
我正在使用代码来绘制烛台:
for row in ohlc:
row[0] = mdates.date2num(datetime.datetime.fromtimestamp(row[0]))
fig = plt.figure()
ax1 = plt.subplot2grid((1,1), (0,0))
candlestick_ohlc(ax1,ohlc,width=0.1)
fig.subplots_adjust(bottom=0.3)
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%y-%m-%d %H:%M:%S'))
for label in ax1.xaxis.get_ticklabels():
label.set_rotation(45)
plt.xlabel('Date')
plt.ylabel('Price')
plt.show()
但烛台被绘制在彼此之上:
当我进一步检查代码时,我注意到它mdates.date2num(datetime.datetime.fromtimestamp(row[0]))
实际上生成的日期差异非常小(因此烛台被绘制在彼此之上):
736558.1997453704
736558.1997569444
736558.1997685186
736558.1997800926
736558.1997916667
736558.1998032407
736558.1998148148
736558.1998263889
736558.199837963
736558.199849537
这个问题的解决方案是什么?
解决方案
推荐阅读
- android - 未调用 onAccessibilityEvent
- vim - vim 删除命令
- ruby-on-rails - NoMethodError:未定义的方法“seconds_to_utc_offset”用于#
- javascript - 在 Angular 1.6 中从 grunt 迁移到 webpack
- ios - 如何折叠 iPhone 上的键盘?
- mongodb - 循环通过排序的mongodb游标时如何避免重复
- vb.net - VB.NET 文本框删除最后一个破折号
- c++ - 同一个文件中的多个对象 - 如何创建 Makefile?
- r - R plot_ly hoverinfo
- android - 渲染错误:无法在当前主题中找到样式“coordinatorLayoutStyle”