"""
Created on Fri Apr 7 16:41:01 2017
@author: Administrator
"""
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter, WeekdayLocator, DayLocator, MONDAY,YEARLY
from matplotlib.finance import quotes_historical_yahoo_ohlc, candlestick_ohlc
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
ticker = '600028'
ticker += '.ss'
date1 = (2017, 3, 5)
date2 = (2017, 4, 8)
mondays = WeekdayLocator(MONDAY)
alldays = DayLocator()
mondayFormatter = DateFormatter('%m-%d-%Y')
dayFormatter = DateFormatter('%d')
quotes = quotes_historical_yahoo_ohlc(ticker, date1, date2)
if len(quotes) == 0:
raise SystemExit
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(mondayFormatter)
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()