python.pygal/reuqests学习范例-爬取github上Python热度并数据化显示
来源:互联网 发布:手机熊猫登录网络 编辑:程序博客网 时间:2024/06/11 15:29
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'
r=requests.get(url)
print('status code: ',r.status_code)
#将API响应存储在一个变量中
response_dict=r.json()
#指出GitHub包含多少python仓库
print("Total repositories: ",response_dict['total_count'])
#探索有关仓库的信息
repo_dicts=response_dict['items']
print("number of items: ",len(repo_dicts))
names,plot_dicts=[],[]
for repo_dict in repo_dicts:
names.append(repo_dict['name']) #为生成x轴的标签
plot_dict={'value':repo_dict["stargazers_count"],
'label':str(repo_dict["description"]),
'xlink':repo_dict['html_url'],
} #value为值,label为描述,xlink为添加的链接
plot_dicts.append(plot_dict) #为生成存储的值和项目描述(点击条形图,出现描述)
#可视化
my_style=LS('#333366',base_style=LCS)
#配置图表格式
my_config=pygal.Config()
my_config.x_label_rotation=45 #x轴标签旋转45度
my_config.show_legend=False #隐藏图例
my_config.title_font_size=24 #设置标题字体
my_config.label_font_size=14 #设置副标签字体
my_config.major_label_font_size=18 #设置主标签字体
my_config.truncate_label=15 #将较长的项目名缩短为15个字符
my_config.show_y_guides=False #隐藏图标的水平线
my_config.width=1000 #自定义图标宽度
#bar创建条形图
chart=pygal.Bar(my_config,style=my_style)
chart.title='most-starred python projects on github'
chart.x_labels=names
chart.add('',plot_dicts) #空字符串不需给数据添加标签
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'
r=requests.get(url)
print('status code: ',r.status_code)
#将API响应存储在一个变量中
response_dict=r.json()
#指出GitHub包含多少python仓库
print("Total repositories: ",response_dict['total_count'])
#探索有关仓库的信息
repo_dicts=response_dict['items']
print("number of items: ",len(repo_dicts))
names,plot_dicts=[],[]
for repo_dict in repo_dicts:
names.append(repo_dict['name']) #为生成x轴的标签
plot_dict={'value':repo_dict["stargazers_count"],
'label':str(repo_dict["description"]),
'xlink':repo_dict['html_url'],
} #value为值,label为描述,xlink为添加的链接
plot_dicts.append(plot_dict) #为生成存储的值和项目描述(点击条形图,出现描述)
#可视化
my_style=LS('#333366',base_style=LCS)
#配置图表格式
my_config=pygal.Config()
my_config.x_label_rotation=45 #x轴标签旋转45度
my_config.show_legend=False #隐藏图例
my_config.title_font_size=24 #设置标题字体
my_config.label_font_size=14 #设置副标签字体
my_config.major_label_font_size=18 #设置主标签字体
my_config.truncate_label=15 #将较长的项目名缩短为15个字符
my_config.show_y_guides=False #隐藏图标的水平线
my_config.width=1000 #自定义图标宽度
#bar创建条形图
chart=pygal.Bar(my_config,style=my_style)
chart.title='most-starred python projects on github'
chart.x_labels=names
chart.add('',plot_dicts) #空字符串不需给数据添加标签
chart.render_to_file('python_repo.svg')
阅读全文
0 0
- python.pygal/reuqests学习范例-爬取github上Python热度并数据化显示
- python处理JSON格式数据并利用pygal绘制世界地图
- python.pygal/random学习范例-模拟掷六面骰子点数次数生成直方图
- python.json/pygal.maps.world学习范例-读取json格式文件、生成世界地图
- #python学习笔记#使用python爬取网站数据并保存到数据库
- python定期爬取GitHub上每日流行项目
- python网络数据采集学习范例—利用CSS爬取网站特定标签,BeautifulSoup函数介绍及子标签
- Python进阶 -- 2. pygal
- python报表(pygal)
- python pygal绘制直方图
- python学习,爬取淘宝评论数据
- 【原创】python Reuqests&nbs…
- python爬取数据
- python使用pygal进行绘制数据图表和监控图表
- python使用pygal进行绘制数据图表和监控图表
- 读书笔记-python,数据可视化之Pygal的使用
- Python爬取数据并写入MySQL数据库
- python爬取数据并将其存入mongodb
- Spring 静态工厂和实例工厂
- Redis学习日志(二)
- 用QPluginLoader做插件,也就是动态类。
- 3D齐次变换命令目录
- android 跳转当前app权限页面
- python.pygal/reuqests学习范例-爬取github上Python热度并数据化显示
- 链表G 双向链表
- C++产生随机数简单例子
- AI:虚拟鱼的遗传演化
- 设计模式——代理模式
- 链表H 链表的逆置
- 值得推荐的C/C++框架和库
- [siggraph17]decima engine的光照和aa技术
- 链表I 约瑟夫问题(删除+计数!典题)