中易网

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

答案:2  悬赏:30  
解决时间 2021-04-21 07:39
怎么利用python代码绘制k线图
最佳答案
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()
全部回答
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' # 600028 是"中国石化"的股票代码 ticker += '.ss'   # .ss 表示上证 .sz表示深证 date1 = (2015, 8, 1) # 起始日期,格式:(年,月,日)元组 date2 = (2016, 1, 1)  # 结束日期,格式:(年,月,日)元组 mondays = weekdaylocator(monday)            # 主要刻度 alldays = daylocator()                      # 次要刻度 #weekformatter = dateformatter('%b %d')     # 如:jan 12 mondayformatter = dateformatter('%m-%d-%y') # 如:2-29-2015 dayformatter = dateformatter('%d')          # 如:12 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) #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()
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
谁能给个金山毒霸通行证
娥佩兰新版调量睫毛液11#带纤毛和1#不带纤毛
重庆轻轨晚上几点收班?三号线和一号线……求
蜂蜜配方是蜂蜜,低聚果糖,低聚异麦芽糖,是真
我的电脑中毒了?
游泳时间与水温有何关联
手机玩GBA游戏的问题
马丁D28木吉他和ovation电箱同级别价位的木吉
美寸代餐 带哪一餐效果会更好一点啊
安徽金寨县出了多少将军
什么金属能造出最好的刀
什么时候要考虑盐类的水解和弱电解质继续电离
关于燃气热水器打火问题
宝宝抵抗力太低了 我该怎么办
以快乐假日为主题的手抄报应该写什么内容
推荐资讯
蒙城有没有西点蛋糕面包烘焙培训班
西安出租车公司叫车电话
梦见居士说教什么意思
学电子琴能做艺术特长生参加高考吗
开家特色小吃店的具体流程?
安顺市惠龙易通电商物流有限公司我想知道这个
我去年椎间盘突出,到现在已有一年光景了,现
skype是什么东西
关于F调竹笛的问题
氙气灯为何开一分钟就自己熄了
谁有QQ炫舞1.49全P补丁挂?
九朵云奇迹马油霜 油性皮肤可以用吗
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?