這篇文章帶給大家的內容是關於Python中matplotlib庫的用法介紹,有一定的參考價值,有需要的朋友可以參考一下,希望對你有幫助。
介紹
matplotlib函式庫是Python中的一個2D繪圖函式庫。
安裝
$ pip install matplotlib
入門
繪製折線圖
pyplot函數繪製折線圖
這裡畫一個月份與溫度的折線圖:
import matplotlib.pyplot as plt x_month = [3,4,5,6,7,8,9] y_temperature = [18,24,27,30,35,37,31] plt.plot(x_month,y_temperature) plt.show() # plt.savefig('xxx.png') # 保存图标函数
這裡導入pyplot模組並將其命名為plt。 show()
用來展示圖片。 savefig()
則用來儲存圖片。
設定x,y軸
import matplotlib.pyplot as plt x_month = [1,2,3,4,5,6,7,8] y_temperature = [11,22,23,43,20,23,42,42] plt.plot(x_month,y_temperature,linewidth=5) # linewidth定义折线宽度 plt.title("This is Title") # 标题 plt.xlabel("month",fontsize=14) # x轴 plt.ylabel("temperature",fontsize=14) # y轴 plt.tick_params(axis='both',labelsize=14) # 影响xy刻度的函数 plt.show() # 展示 # plt.savefig('xxx.png') # 保存图标函数
fontsize
用來設定各軸的字體大小。
繪製單點圖
scatter函數繪製單點圖
import matplotlib.pyplot as plt plt.scatter(1,8,s=50,c='red') plt.show()
參數s
設定了繪製圖形時使用的點的尺寸。 c
參數設定點的顏色,也可以用RDB方式來指定:c=(0,0,0.8)
繪製一系列點
import matplotlib.pyplot as plt x_values = list(range(1001)) y_values = [x**2 for x in x_values] plt.scatter(x_values,y_values,s=40,edgecolors='none') # edgecolors参数用于去除外轮廓 plt.show()
edgecolors
可以指定white
或black
等。
繪製顏色映射圖
import matplotlib.pyplot as plt x_values = list(range(1001)) y_values = [x**2 for x in x_values] plt.scatter(x_values,y_values,s=40,edgecolors='none',c=y_values,cmap=plt.cm.Blues)
將y_values參數傳入c
中,並使用cmap
告訴函數使用哪個顏色進行映射。
以上是Python中matplotlib函式庫的用法介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!

forloopsareadvantageousforknowniterations and sequests,供應模擬性和可讀性;而LileLoopSareIdealFordyNamicConcitionSandunknowniterations,提供ControloperRoverTermination.1)forloopsareperfectForeTectForeTerToratingOrtratingRiteratingOrtratingRitterlistlistslists,callings conspass,calplace,cal,ofstrings ofstrings,orstrings,orstrings,orstrings ofcces

pythonisehybridmodeLofCompilation和interpretation:1)thepythoninterpretercompilesourcecececodeintoplatform- interpententbybytecode.2)thepythonvirtualmachine(pvm)thenexecutecutestestestestestesthisbytecode,ballancingEaseofuseEfuseWithPerformance。

pythonisbothinterpretedAndCompiled.1)它的compiledTobyTecodeForportabilityAcrosplatforms.2)bytecodeisthenInterpreted,允許fordingfordforderynamictynamictymictymictymictyandrapiddefupment,儘管Ititmaybeslowerthananeflowerthanancompiledcompiledlanguages。

在您的知識之際,而foroopsareideal insinAdvance中,而WhileLoopSareBetterForsituations則youneedtoloopuntilaconditionismet

ForboopSareSusedwhenthentheneMberofiterationsiskNownInAdvance,而WhileLoopSareSareDestrationsDepportonAcondition.1)ForloopSareIdealForiteratingOverSequencesLikelistSorarrays.2)whileLeleLooleSuitableApeableableableableableableforscenarioscenarioswhereTheLeTheLeTheLeTeLoopContinusunuesuntilaspecificiccificcificCondond

pythonisnotpuroly interpred; itosisehybridablectofbytecodecompilationandruntimeinterpretation.1)PythonCompiLessourceceCeceDintobyTecode,whitsthenexecececected bytybytybythepythepythepythonvirtirtualmachine(pvm).2)

concatenateListSinpythonWithTheSamelements,使用:1)operatoTotakeEpduplicates,2)asettoremavelemavphicates,or3)listcompreanspherensionforcontroloverduplicates,每個methodhasdhasdifferentperferentperferentperforentperforentperforentperfornceandordorimplications。

pythonisanterpretedlanguage,offeringosofuseandflexibilitybutfacingperformancelanceLimitationsInCricapplications.1)drightingedlanguageslikeLikeLikeLikeLikeLikeLikeLikeThonexecuteline-by-line,允許ImmediaMediaMediaMediaMediaMediateFeedBackAndBackAndRapidPrototypiD.2)compiledLanguagesLanguagesLagagesLikagesLikec/c thresst


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Dreamweaver CS6
視覺化網頁開發工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Dreamweaver Mac版
視覺化網頁開發工具

禪工作室 13.0.1
強大的PHP整合開發環境