python.pygal/reuqests学习范例-爬取github上Python热度并数据化显示
2017-10-03 19:09
225 查看
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) #空字符串不需给数据添加标签
chart.render_to_file('python_repo.svg')
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')
相关文章推荐
- python.json/pygal.maps.world学习范例-读取json格式文件、生成世界地图
- Python pyQt4/pyQt5 学习笔记1(空白窗口,按钮,控件事件,控件提示,窗体显示到屏幕中间,messagebox)
- vim+python+OpenCV学习五 : 直方图的计算与显示
- Python学习-中文显示乱码
- pygame学习和python巩固——字体显示
- 【原创】python Reuqests&nbs…
- Python学习笔记(二)-NotePad++中文显示问题
- 【python学习.Github上的代码】
- 深度学习--python 读取并显示图片的方法
- 【Python学习笔记】-APP图标显示未读消息数目
- 【学习Python】Python图像处理(2):图像显示
- Python学习pygal绘制线图代码分享
- python网络数据采集学习范例—利用CSS爬取网站特定标签,BeautifulSoup函数介绍及子标签
- 【基于C++和Python的Opencv3学习笔记之图像载入、显示和保存】
- python聚类算法以及图像显示结果--python学习笔记23
- python学习--下载--下载固定文件显示下载百分之的进度
- python.matplotlib/datatime/CSV学习范例-读取CSV格式文件生成折线图
- python opencv入门(学习笔记no.3)-从摄像头读取视频并显示
- python学习之路之案例3--多级菜单显示城市详细信息
- Python学习篇之-手机号中间加密显示