Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- import requests
- import matplotlib.dates as mdates
- def graph_data():
- stock_price_url = 'https://pythonprogramming.net/yahoo_finance_replacement'
- response = requests.get(stock_price_url)
- source = response.content.decode('UTF-8')
- split_source = source.splitlines()
- # remove headers
- del split_source[0]
- stock_data = []
- for line in split_source:
- split_line = line.split(',')
- if not len(split_line) == 7:
- continue
- stock_data.append(line)
- date, open, high, low, closep, ajd_close, volume = np.loadtxt(stock_data,
- delimiter=',',
- unpack=True,
- converters=
- {0: lambda x: mdates.datestr2num(x.decode('utf8'))})
- plt.plot_date(date,closep, '-', label='Price')
- plt.xlabel('Date')
- plt.ylabel('Price')
- plt.legend()
- plt.show()
- graph_data()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement