使用pygal绘图l时语法错误
我想把一个含有股价信息json文件做成可视化图表,然后在创建图表时报错了。我的代码:
from itertools import groupby
import json
import pygal
import math
#put data into a list
filename = 'btc_close_2017.json'
with open(filename) as f:
btc_data = json.load(f)
#create 5 list to instore date and close price
dates = []
months = []
weeks = []
weekdays = []
close = []
#print everyday's message
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'])))
def draw_line(x_data,y_data,title,y_legend):
xy_map = []
for x,y in groupby(sorted(zip(x_data,y_data)),key=lambda _:_):
y_list =
xy_map.append()
x_unique,y_mean = [*zip(*xy_map)]
line_chart = pygal.Line()
line_chart.title = title
line_chart.x_label = x_unique
line_chart.add(y_legend,y_mean)
line_chart.render_to_file(title+'.svg')
return line_chart
idx_week = dates.index('2017-12-11')
wd = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
weekdays_int =
line_chart_weekday = draw_line(weekdays_int,close,'a','b')
line_chart_weekday.x_labels = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
line_chart_weekday.render_to_file('close price of week average.svg')
发生了语法错误,实在看不出来哪里错了:
File "btc_close_price_week_average.py", line 43
line_chart_weekday = draw_line(weekdays_int,close,'a','b')
^
SyntaxError: invalid syntax weekdays_int =
最后面少了个]吧?
就是报错的上面一行
这个库绘图,和matplotlib比,特点在哪? 疾风怪盗 发表于 2020-10-29 22:56
最后面少了个]吧?
就是报错的上面一行
大佬能讲一下常见的排查错误的方法吗,我就只会盯着报错的那一句 张图南 发表于 2020-10-29 22:58
大佬能讲一下常见的排查错误的方法吗,我就只会盯着报错的那一句
这个。。。。。。。没法说,我是用pycharm来敲代码的,会有点错误提示
多敲点代码,bug多一点,就会了。。。。。。。。。 疾风怪盗 发表于 2020-10-29 22:56
最后面少了个]吧?
就是报错的上面一行
pygal的特点是画的图是SVG格式,用浏览器打开。matplotlib能画出PNG格式的图。 张图南 发表于 2020-10-29 23:01
pygal的特点是画的图是SVG格式,用浏览器打开。matplotlib能画出PNG格式的图。
哦。。。。。。。没用过svg格式。。。。。。
页:
[1]