Python 画股票收盘价折线图

版权声明:转载请注明原文地址即可,要是本文对您有些许帮助的话,请您在下方点个赞,谢谢啦ヾ(o◕∀◕)ノヾ https://blog.csdn.net/qq_33583069/article/details/89055849

# from __future__ import(absolute_import,division,print_function,unicode_literals)
# try:
#     from urllib2 import urlopen #python 2.x
# except ImportError:
#     from urllib.request import urlopen #python 3.x
# import json
# import requests
# json_url = 'https://raw.githubusercontent.com/muxuezi/btc/master/btc_close_2017.json'
# response = urlopen(json_url)
# req = response.read()
# req = requests.get(json_url)
# with open('btc_close_2017_urllib.json','wb') as f:
#     f.write(req)
# with open('btc_close_2017_urllib.json','w') as f:
#     f.write(req.text)
# file_urllib = json.loads(req)
# print(file_urllib)
# file_requests = req.json()
# print(file_requests)
import json
import pygal
dates = []
months = []
weeks = []
weekdays = []
close = []
filename = 'btc_close_2017.json'
with open(filename) as f:
    btc_data = json.load(f)
for btc_dict in btc_data:
    dates.append(btc_dict['date'])
    months.append(int(btc_dict['month']))
    weeks.append(int(btc_dict['week']))
    weekdays.append(btc_dict['weekday'])
    close.append(int(float(btc_dict['close'])))
line_chart = pygal.Line(x_label_rotation=20,show_minor_x_labels=False)
line_chart.title = '收盘价(¥)'
line_chart.x_labels = dates
N = 20
line_chart.x_labels_major = dates[::N]
line_chart.add('收盘价',close)
line_chart.render_to_file('收盘价折线图(¥).svg')

猜你喜欢

转载自blog.csdn.net/qq_33583069/article/details/89055849