继matplotlib example我有以下解决方案:
from pylab import *
import matplotlib.pyplot as plt
from datetime import datetime
import time
from matplotlib.dates import DateFormatter, WeekdayLocator, HourLocator, \
DayLocator, MONDAY
from matplotlib.finance import candlestick,\
plot_day_summary, candlestick2
mondays = WeekdayLocator(MONDAY) # major ticks on the mondays
alldays = DayLocator() # minor ticks on the days
weekFormatter = DateFormatter('%b %d') # e.g., Jan 12
dayFormatter = DateFormatter('%d') # e.g., 12
#starting from dates expressed as strings...
Date1 = '01/01/2010'
Date2 = '02/01/2010'
#...you convert them in float numbers....
Date1 = date2num(datetime.strptime(Date1, "%d/%m/%Y"))
Date2 = date2num(datetime.strptime(Date2, "%d/%m/%Y"))
#so redefining the Prices list of tuples...
Prices = [(Date1, 1.123, 1.212, 1.463, 1.056), (Date2,1.121, 1.216, 1.498, 1.002)]
#and then following the official example.
fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.2)
ax.xaxis.set_major_locator(mondays)
ax.xaxis.set_minor_locator(alldays)
ax.xaxis.set_major_formatter(weekFormatter)
candlestick(ax, Prices, width=0.6)
ax.xaxis_date()
ax.autoscale_view()
plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')
plt.show()
有什么不对的'candlestick' http://matplotlib.org/examples/pylab_examples/finance_demo.html matplotlib自己的例子吗?你只需要适应你的数据(为此我们有btw不知道你想要什么绘图)。 –
只是不理解如何构建我的数据,因为它不是显式的: 'quotes = quotes_historical_yahoo('INTC',date1,date2)'。 但现在我已经发现[这里](http://doc.astro-wise.org/matplotlib.finance.html)它必须是“引号是一系列的(时间,开放,关闭,高,低,...)序列“。所以现在它起作用了,我的只是一个普通的问题,因为我已经看到,在网络中很难找到一个非常基本的例子,很多时候用户更喜欢使用他们自己的数据而不是雅虎财经的数据。不管怎么说,还是要谢谢你。 –
您的问题留下了重要的细节,以备将来参考。也许你可以写下你希望烛台图显示哪些信息,以及“价格”中的不同字段究竟代表什么。 –