编写一个能将股票数据可视化显示的小程序。
plt.legend()的几种用法
python函数之xticks实现时间作为横坐标并按指定间隔显示
Python学习:matplotlib模块——plt.savefig存储文件
Python基本函数:plot()
Python--Matplotlib(基本用法)python设置字体_python 设置xlabel,ylabel 坐标轴字体大小,字体类型
思路:用自定义read和open将表格用列表读出
用plot一个一个画图,用legend将图合并并用savefig保存
第一次发,欢迎大家批评指正,一起进步
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
# 不要改变上面的顺序
import datetime
def Draw():
appl = "step3/AAPL.csv" #苹果
google = "step3/GOOG.csv" #谷歌
ms = "step3/MSFT.csv" #微软
#在此绘制折线图
# 请在此添加实现代码 #
# ********** Begin *********#
plt.xticks(rotation =45)
appdate,appopens = Read(open(appl))
plt.plot(appdate,appopens,color = 'red',linewidth = 1.0,label="appl")
gogdate,gogopens = Read(open(google))
plt.plot(gogdate,gogopens,color = 'green',linewidth = 1.0,label="goog")
msdate,msopens = Read(open(ms))
plt.plot(msdate,msopens,color = 'blue',linewidth = 1.0,label="ms")
plt.legend(["Apple","Google","Microsoft"])
plt.ylabel("Open")
plt.savefig("step3/output/data.png")
# ********** End **********#
plt.savefig("step3/output/data.png")
#如果有必要,可以增加别的函数协助完成任务,可在此添加实现代码
# ********** Begin *********#
def Read(file):
dates=[]
opens=[]
file.readline()
for line in file.readlines():
i1 = line.index(",",0,len(line))
dt = datetime.datetime.strptime(line[0:i1],"%Y-%m-%d").date()
dates.append(dt)
i2 = line.index(",",i1+1,len(line))
opens.append(float(line[i1+1:i2]))
file.close()
return dates,opens
# ********** End **********#



