实际上,除了你已经拥有的东西之外,没有理由做任何事情。 Matplotlib 将为您处理转换。
听起来你有一个时间序列列表,开盘、收盘、高低?
类似:
from datetime import datetime
# date open close high low
quotes = [(datetime(2012, 2, 1), 103.62, 102.01, 103.62, 101.90),
(datetime(2012, 2, 2), 102.24, 102.90, 103.16, 102.09),
...
(datetime(2012, 4, 12), 100.89, 102.59, 102.86, 100.51)]
这实际上是 matplotlib 的烛台函数所期望的确切数据结构。
您只需要将日期时间转换为 matplotlib 的内部日期格式。使用matplotlib.dates.date2num。
例如
from matplotlib.dates import date2num
# I'm assuming you have tuples, so we can't modify them in-place...
quotes = [(date2num(item[0]),) + item[1:] for item in quotes]
除此之外,请查看一些 matplotlib 财务示例。 This one is a good start.