【发布时间】:2018-08-22 19:38:42
【问题描述】:
import requests
import pygal
from pygal.style import LightColorizedStyle as LCS, LightenStyle as LS
url = "https://api.github.com/search/repositories?
q=language:python&sort=stars"
r = requests.get(url)
response_dict = r.json()
names,stars = [],[]
for repo in repo_dicts:
names.append(repo["name"])
stars.append(repo["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("repo_visual.svg")
运行此代码时,我得到一个 AttributeError。 我正在尝试使用 pygal 模块将星星最多的 python 项目绘制到条形图上。该任务来自 Eric Matthes 的 Python 速成课程。我正在和他的代码交叉检查我的代码,我似乎找不到任何问题
追踪:
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/generatingdata/python_repos.py", line
51, in <module>
chart.render_to_file("x.svg")
非常感谢任何帮助。
【问题讨论】:
-
欢迎来到 StackOverflow!包含堆栈跟踪通常会有所帮助,这样导致错误的行就很明显了。