This article brings you the use cases (code) of the matplotlib module in Python. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
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('图片保存成功.')
The result is:
This is actually relatively simple, just take out the json data and visualize it with matplotlib.
The above is the entire content of this article. For more exciting content about python, you can pay attention to the php Chinese website Python video tutorial and python article tutorial! ! !
The above is the detailed content of Use cases of matplotlib module in Python (code). For more information, please follow other related articles on the PHP Chinese website!

Python is an interpreted language, but it also includes the compilation process. 1) Python code is first compiled into bytecode. 2) Bytecode is interpreted and executed by Python virtual machine. 3) This hybrid mechanism makes Python both flexible and efficient, but not as fast as a fully compiled language.

Useaforloopwheniteratingoverasequenceorforaspecificnumberoftimes;useawhileloopwhencontinuinguntilaconditionismet.Forloopsareidealforknownsequences,whilewhileloopssuitsituationswithundeterminediterations.

Pythonloopscanleadtoerrorslikeinfiniteloops,modifyinglistsduringiteration,off-by-oneerrors,zero-indexingissues,andnestedloopinefficiencies.Toavoidthese:1)Use'i

Forloopsareadvantageousforknowniterationsandsequences,offeringsimplicityandreadability;whileloopsareidealfordynamicconditionsandunknowniterations,providingcontrolovertermination.1)Forloopsareperfectforiteratingoverlists,tuples,orstrings,directlyacces

Pythonusesahybridmodelofcompilationandinterpretation:1)ThePythoninterpretercompilessourcecodeintoplatform-independentbytecode.2)ThePythonVirtualMachine(PVM)thenexecutesthisbytecode,balancingeaseofusewithperformance.

Pythonisbothinterpretedandcompiled.1)It'scompiledtobytecodeforportabilityacrossplatforms.2)Thebytecodeistheninterpreted,allowingfordynamictypingandrapiddevelopment,thoughitmaybeslowerthanfullycompiledlanguages.

Forloopsareidealwhenyouknowthenumberofiterationsinadvance,whilewhileloopsarebetterforsituationswhereyouneedtoloopuntilaconditionismet.Forloopsaremoreefficientandreadable,suitableforiteratingoversequences,whereaswhileloopsoffermorecontrolandareusefulf

Forloopsareusedwhenthenumberofiterationsisknowninadvance,whilewhileloopsareusedwhentheiterationsdependonacondition.1)Forloopsareidealforiteratingoversequenceslikelistsorarrays.2)Whileloopsaresuitableforscenarioswheretheloopcontinuesuntilaspecificcond


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1
Easy-to-use and free code editor
