想把数据可视化出现报错了,请问有会的吗?
import requests
import pygal
from pygal.style import LightColorizedStyle as LCS, LightenStyle as LS
执行API调用并存储响应
url='
https://api.github.com/search/repositories?q=language:python&sort=stars'
https://api.github.com/search/repositories?q=language:python&sort=stars%27
r = requests.get(url)
print("Status code:",r.status_code)
将API响应存储在一个变量中
response_dict=r.json()
print("Total repositors:",response_dict['total_count'])
探索有关仓库的信息
repo_dicts=response_dict['items']
names,stars=[],[]
print("Repositories returned:",len(repo_dicts))
研究第一个仓库
repo_dict = repo_dicts[0]
print("\nkeys:",len(repo_dict)):
for key in sorted(repo_dict.keys()):
print(key)
print("\nSelected information about each repository:")
for repo_dict in repo_dicts:
names.append(repo_dict['name'])
stars.append(['stargazers_count'])
#可视化
my_style=LS('#333360',base_style=LCS)
chart=pygal.Bar(style=my_style,x_label_rotation=45,show_legend=False)
chart.title='Most-Starred Python Projects on GitHub'
chart.x_labels=names
chart.add('',stars)
chart.render_to_file('python_repos.svg')
print('\nName:',repo_dict['name'])
print('Owner:',repo_dict['owner']['login'])
print('Stars:',repo_dict['stargazers_count'])
print('Repository:',repo_dict['html_url'])
print('Created:',repo_dict['created_at'])
print('Updated:',repo_dict['updated_at'])
print('Description:',repo_dict['description'])
E:\pythonProject\Scripts\python.exe E:/PycharmProjects/pythonProject/web/python_repos.py
Status code: 200
Total repositors: 7710879
Traceback (most recent call last):
File "E:\PycharmProjects\pythonProject\web\python_repos.py", line 26, in
chart.render_to_file('python_repos.svg')
File "E:\pythonProject\lib\site-packages\pygal\graph\public.py", line 114, in render_to_file
f.write(self.render(is_unicode=True, **kwargs))
File "E:\pythonProject\lib\site-packages\pygal\graph\public.py", line 52, in render
self.setup(**kwargs)
File "E:\pythonProject\lib\site-packages\pygal\graph\base.py", line 217, in setup
self._draw()
File "E:\pythonProject\lib\site-packages\pygal\graph\graph.py", line 923, in _draw
self._compute()
File "E:\pythonProject\lib\site-packages\pygal\graph\bar.py", line 132, in _compute
self._box.ymin = min(self._min, self.zero)
TypeError: '<' not supported between instances of 'int' and 'list'
进程已结束,退出代码为 1