使用python入门可视化数据求助

INCREIBLE_TIGER 2021-03-30 12:17:08

import requests
import pygal
from pygal.style import LightColorizedStyle as LCS, LightStyle as LS

# 执行API调用并存储响应
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
r = requests.get(url)
print("Status code:", r.status_code)

# 将API响应存储在一个变量中
response_dict = r.json()
print("Total repositories:",response_dict['total_count'])

# 探索有关仓库的信息
repo_dicts = response_dict['items']

names, stars = [], []
for repo_dict in repo_dicts:
names.append(repo_dict['name'])
stars.append(repo_dict['stargazers_count'])

# 可视化
my_style = LS('#333366', 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')


结果为什么报这种错,我都是按照书上打的,pygal也装了啊
line 23, in <module>
my_style = LS('#333366', base_style=LCS)
TypeError: __init__() takes 1 positional argument but 2 were given
...全文
152 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
m0_57858081 2021-08-22
  • 打赏
  • 举报
回复 4

my_style = LS('#333366', base_style=LCS) 中少了c=
应该为my_style = LS(c='#333366', base_style=LCS)

2,209

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 其他数据库
社区管理员
  • 其他数据库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧