#!/usr/bin/env python
from pylab import *
from matplotlib.finance import candlestick
from datetime import datetime
data2 = [(datetime(2012, 2, 1), 3103, 3102.01, 3103.62, 3101.90),
(datetime(2012, 2, 1), 3102, 3102.90, 3103.16, 3102.09),
(datetime(2012, 2, 2), 3100.89, 3102.59, 3102.86, 3100.51),
(datetime(2012, 2, 3), 3103.62, 3102.01, 3103.62, 3101.90),
(datetime(2012, 2, 5), 3102.24, 3102.90, 3103.16, 3102.09),
(datetime(2012, 2, 6), 3100.89, 3102.59, 3102.86, 3100.51)]
quotes = [(date2num(item[0]),) + item[1:] for item in data2]
fig = figure()
fig.subplots_adjust(bottom=0.2)
ax = fig.add_subplot(111)
ax.xaxis.set_major_locator(mondays)
ax.xaxis.set_minor_locator(alldays)
ax.xaxis.set_major_formatter(weekFormatter)
candlestick(ax, quotes, width=0.6)
ax.xaxis_date()
ax.autoscale_view()
setp( gca().get_xticklabels(), rotation=45, horizontalalignment='right')
show()
这很好用并绘制了烛台图。这似乎与read_command_line(prog_args_array)
:
def read_command_line(prog_args_array):
prog = prog_args_array.pop(0)
parser = argparse.ArgumentParser(description=__doc__, prog=prog)
parser.add_argument('--version', action='version', version=VERSION)
return parser.parse_args(prog_args_array)
def main(prog_args_array):
args = read_command_line(prog_args_array)
...
if __name__ == '__main__':
sys.exit(main(sys.argv))
这给了我这个:
Traceback (most recent call last):
File "./tdseq4.py", line 124, in <module>
sys.exit(main(sys.argv))
File "./tdseq4.py", line 89, in main
fig = figure()
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 343, in figure
**kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 80, in new_figure_manager
window = Tk.Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1683, in __init__
baseName = os.path.basename(sys.argv[0])
IndexError: list index out of range
make: *** [all] Error 1