k线图python代码_怎么利用python代码绘制k线图

2017-03-31 回答

import matplotlib.pyplot as pltfrom matplotlib.dates import dateformatter, weekdaylocator, daylocator, monday,yearlyfrom matplotlib.finance import quotes_historical_yahoo_ohlc, candlestick_ohlcplt.rcparams['font.sans-serif'] = ['simhei']plt.rcparams['axes.unicode_minus'] = falseticker = '600028' # 600028 是"中国石化"的股票代码ticker += '.ss' # .ss 表示上证 .sz表示深证date1 = (2015, 8, 1) # 起始日期,格式:(年,月,日)元组date2 = (2016, 1, 1) # 结束日期,格式:(年,月,日)元组mondays = weekdaylocator(monday) # 主要刻度alldays = daylocator() # 次要刻度#weekformatter = dateformatter('%b %d') # 如:jan 12mondayformatter = dateformatter('%m-%d-%y') # 如:2-29-2015dayformatter = dateformatter('%d') # 如:12quotes = quotes_historical_yahoo_ohlc(ticker, date1, date2)if len(quotes) == 0: raise systemexitfig, 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(mondayformatter)#ax.xaxis.set_minor_formatter(dayformatter)#plot_day_summary(ax, quotes, ticksize=3)candlestick_ohlc(ax, quotes, width=0.6, colorup='r', colordown='g')ax.xaxis_date()ax.autoscale_view()plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')ax.grid(true)plt.title('中国石化 600028')plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值