python分析上证指数

import xlrd
import xlwt
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from pylab import mpl
pngFile = 'google_stock_trend.png'
mpl.rcParams['font.sans-serif'] = ['SimHei'] # 指定默认字体
mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题,中文显示不乱码
workBook = xlrd.open_workbook('/home/0.xls')
allSheetNames = workBook.sheet_names()
print(allSheetNames)
plt.figure(figsize=(1000,1000))
plt.figure(dpi=300)
# 1.2 按索引号获取sheet的名字(string类型)
sheet1Name = workBook.sheet_names()[0];
print(sheet1Name);
# 2. 获取sheet内容
## 2.1 法1:按索引号获取sheet内容
sheet1_content1 = workBook.sheet_by_index(0); # sheet索引从0开始
## 2.2 法2:按sheet名字获取sheet内容
# sheet1_content2 = workBook.sheet_by_name('Sheet1');
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(18.5, 10.5)
# 3. sheet的名称,行数,列数
print(sheet1_content1.name,sheet1_content1.nrows,sheet1_content1.ncols);
plt.style.use('seaborn-whitegrid')
x = range(1,7216,1000)
plt.xticks(x,rotation=30)

plt.plot(sheet1_content1.col_values(0),sheet1_content1.col_values(6),label='open',marker='o', linestyle=':', linewidth=1, markersize=3, color='gray')
plt.legend()
plt.title("stock trend")
plt.show(block=True)
fig.savefig(pngFile)

plt.close()
...
原文地址:https://www.cnblogs.com/javage/p/13220700.html