用Python绘制数据故障

时间:2015-09-03 19:51:34

标签: python pandas matplotlib yahoo

我试图创建一个程序,允许我创建一个随机10年间隔的股票线图。我可以使用pandas将数据导入DataFrame,但是当我尝试绘制信息时,它不会拉动任何图形。没有错误,所以我不知道会出现什么问题。任何帮助,将不胜感激。

import requests
import numpy as np 
from urllib2 import urlopen
import csv
import pandas as pd
from pandas import *
from pandas import DataFrame as df 

import datetime
import pandas.io.data
from random import randint
import matplotlib.pyplot as plt


YahooUrl = 'http://ichart.yahoo.com/table.csv?s='
start_month = 1 - 1
start_day = 1
start_year = 2010

end_month = 12 - 1
end_day = 31
end_year = 2014

Start_ApiMonth = '&a=%s' %(start_month)
Start_ApiDay = '&b=%s' %(start_day)
Start_ApiYear = '&c=%s' %(start_year)

End_ApiMonth = '&d=%s' %(end_month)
End_ApiDay = '&e=%s' %(end_day)
End_ApiYear = '&f=%s' %(end_year)

interval = 'm'

ApiInterval = '&g=%s' %(interval)

ApiStatic = '&ignore=.csv'

Ticker = 'aapl'

Website = urlopen(YahooUrl + Ticker + Start_ApiMonth + Start_ApiDay +     Start_ApiYear + End_ApiMonth + End_ApiDay + End_ApiYear + ApiInterval +  ApiStatic) 

Info = pd.read_csv(Website)
Table = df(Info)

def Interval():
    end = randint(9,len(Table))
    start = end-10
    group = [start]
    while start <= end:
        group.append(start+1)
        start = start + 1
    return group

interval = Interval()

TableGraph = []
TableGraph = Table['Adj Close'][interval]


points = []
for i in interval:
    points.append(Table['Adj Close'][i])

TG = DataFrame(points, index=list('abcdefghijkl'), columns=list('x'))

TG.plot()

print Table 

1 个答案:

答案 0 :(得分:2)

你需要在剧情后调用show:

plt.show()

这会给你类似的东西:

enter image description here