关于Python matplotlib pyplot的问题
我想得到两张折线图,关于微软和英特尔的股票数据的,代码如下
import time
from matplotlib.finance import quotes_historical_yahoo_ochl
from datetime import date
from datetime import datetime
import pandas as pd
import matplotlib.pyplot as plt
import pylab as pl
import numpy as np
start = datetime(2014,1,1)
end = datetime(2014,12,31)
print start
quotesMSFT = quotes_historical_yahoo_ochl('MSFT',start,end)
quotesINTC = quotes_historical_yahoo_ochl('INTC',start,end)
fieIds = ['date', 'open', 'close', 'high', 'low', 'volume']
list1=[]
for i in range(0,len(quotesMSFT)):
x = date.fromordinal(int(quotesMSFT[i][0]))
y= datetime.strftime(x,"%Y-%m-%d")
list1.append(y)
list2=[]
for i in range(0,len(quotesINTC)):
x= date.fromordinal(int(quotesINTC[i][0]))
y= datetime.strftime(x, "%Y-%m-%d")
list2.append(y)
quotesmsftdf=pd.DataFrame(quotesMSFT,index=list1,columns=fieIds)
quotesmsftdf=quotesmsftdf.drop(['date'],axis=1)
quotesintcdf= pd.DataFrame(quotesINTC,index=list2,columns=fieIds)
quotesintcdf= quotesintcdf.drop(['date'],axis=1)
listtemp1= []
for i in range(0,len(quotesmsftdf)):
temp=time.strptime(quotesmsftdf.index[i], "%Y-%m-%d")
listtemp1.append(temp.tm_mon)
listtemp2 = []
for i in range(0,len(quotesintcdf)):
temp=time.strptime(quotesintcdf.index[i], "%Y-%m-%d")
listtemp2.append(temp.tm_mon)
tempmsftdf=quotesmsftdf.copy()
tempmsftdf['month'] = listtemp1
closemaxMSFT = tempmsftdf.groupby('month').max().close
listMSFT= []
for i in range(1,13):
listMSFT.append(closemaxMSFT[i])
listMSFTIndex= closemaxMSFT.index
tempintcdf= quotesintcdf.copy()
tempintcdf['month']=listtemp2
closemaxINTC = tempintcdf.groupby('month').max().close
listINTC = []
for i in range(1,13):
listINTC.append(closemaxINTC[i])
listINTCIndex = closemaxINTC.index
pl.subplot(211)
plt.plot(listMSFTIndex,listMSFT,color='r',marker='o')
pl.subplot(212)
plt.plot(listINTCIndex,listINTC,color='green',marker='o')
程序运行时没有报错,但是图表却没有显示出来,用的是pycharm
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在最后加上
plt.show()