找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 1609|回复: 1

[求助] 练习《Python编程:从入门到实践》使用Pygal绘制图表时出现...

0

主题

3

帖子

3

积分

贫民

积分
3
aflyrt 发表于 2020-5-16 12:01:48 | 显示全部楼层 |阅读模式
本帖最后由 aflyrt 于 2020-5-16 12:03 编辑

前面确认pygal已经安装
pygal.png


但在练习案例使用到pygal时依然报错,请问是什么情况呢?
  1. # coding:utf-8
  2. import requests
  3. import pygal
  4. from pygal.style import LightColorizedStyle as LCS, LightenStyle as LS
  5. url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
  6. r = requests.get(url)
  7. print("Status code:", r.status_code)
  8. resp**e_dict = r.json()
  9. #print(resp**e_dict.keys())
  10. #打印resp**e_dict.keys()的结果为
  11. #[ 'items', 'total_count',  'incomplete_requests' ]
  12. print('Total repositories: ', resp**e_dict['total_count'])
  13. #探索有关仓库的信息
  14. repo_dicts = resp**e_dict['items']#repo_dicts存贮的是列表,'items'的值是列表
  15. names, stars = [], []
  16. for repo_dict in repo_dicts:
  17.         name.append(repo_dict['name'])
  18.         stars.append(repo_dict['stargazers_count'])
  19. my_style = LS('#333366', base_style = LCS)
  20. chart = pygal.Bar(style = my_style, x_label_rotation = 45, show_legend = False)
  21. chart.title = 'Most - Starred Python Project on GitHub'
  22. chart.x_label = names
  23. chart.add('', stars)
  24. chart.render_to_file('python_repos.svg')
复制代码
编译可以通过,运行后显示如下

运行报错

运行报错

回复

使用道具 举报

0

主题

3

帖子

3

积分

贫民

积分
3
aflyrt  楼主| 发表于 2020-5-16 13:27:22 | 显示全部楼层
顶一顶,别沉下去
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表