iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python的matplotlib模块的
  • 804
分享到

Python的matplotlib模块的

模块Pythonmatplotlib 2023-01-30 22:01:07 804人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

import matplotlib.pyplot as plt import numpy as np import requests url='https://api.GitHub.com/search/repositories?q=

import matplotlib.pyplot as plt
import numpy as np
import requests

url='https://api.GitHub.com/search/repositories?q=language:python&sort=stars'
r=requests.get(url)
print('数据访问状态值:',r.status_code)
print('成功,正常获取网站数据'if r.status_code==200 else '错误,无法获取数据')

response_dict=r.JSON()  #转换成字典
#print(response_dict)
repo_dicts=response_dict['items']
#print(repo_dicts)
names=[repo_dict['name']for repo_dict in repo_dicts]
print(names)
plot_dicts=[repo_dict['stargazers_count'] for repo_dict in repo_dicts]
print(plot_dicts)

x=np.arange(len(names)) #x轴
plt.bar(x,plot_dicts)   #y轴
plt.plot(x,plot_dicts,'rp--') #折线图

ax=plt.subplot()
ax.set_ylabel('stargazers_count') #y轴标题
ax.set_xlabel('github Reponstorys')  #x轴标题

ax.set_xticks(x)  #设置每一个x的标题
ax.set_xticklabels(names,rotation=90) #给每一个柱子加上标题
ax.set_title('Github')


#plt.grid(linestyle='--')  #虚线为背景,一个’-‘为实线,俩个为虚线
#plt.show()
#保存图片
import os
imgPath = os.getcwd() + '/images/ch04_demo05_github.jpg'
plt.savefig(imgPath)
print('图片保存成功.')

结果为:

这个其实比较简单,就是将json数据拿出来,并用matplotlib可视化一下就ok了

--结束END--

本文标题: Python的matplotlib模块的

本文链接: https://www.lsjlt.com/news/179941.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作