import requests
import json
import datetime as dt
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
url = 'http://www.twse.com.tw/exchangeReport/STOCK_DAY?date=%s&stockNo=%s' % ( '20181201', '2892')
r = requests.get(url)
data =json.loads(r.text)
dates = []
y=[]
for row in data['data']:
dateArr =row[0].split("/")
date4=dateArr[1]+"/"+dateArr[2]+"/"+str(int(dateArr[0])+1911)
dates.append(date4)
y.append(row[6])
x = [dt.datetime.strptime(d,'%m/%d/%Y').date() for d in dates]
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y'))
plt.gca().xaxis.set_major_locator(mdates.DayLocator())
plt.plot(x,y)
plt.gcf().autofmt_xdate()
plt.show()
執行結果:
沒有留言:
張貼留言