matplotlib.pyplot 库(一)
matplotlib.pyplot 庫(一)
- 1. matplotlib.pyplt 庫簡介
- 2. matplotlib.pyplot 函數(shù)庫
- 2.1. **plt.figure()**
- 2.2 **plt.subplot()**
- 2.3 **plt.axes()**
- 2.4 plt.subplots_adjust ()
1. matplotlib.pyplt 庫簡介
matplotlib 是 Python 下著名的繪圖庫,matplotlib 通過 pyplot 模塊提供了一套類似和 Matlab 類似的畫圖 API,將眾多繪圖對象所構(gòu)成的復雜結(jié)構(gòu)隱藏在這套 API 內(nèi)部。只需調(diào)用 pyplot 模塊所提供的函數(shù)就可快速繪圖以及設置圖表的各種細節(jié)。
matplotlib.pyplot 的引用方式:import matplot.pyplot as plt
pyplot 模塊重命名為 plt,有助于提高代碼的可讀性,plt 代替 matplotlib.pyplot。
2. matplotlib.pyplot 函數(shù)庫
matplotlib.pyplot 是一個命令型函數(shù)集合,它可以像使用 Matlab 一樣使用 matplotlib,pyplot 中的每一個函數(shù)都會對畫布圖像作出相應的改變。
2.1. plt.figure()
使用 plt.figure() 函數(shù)創(chuàng)建一個全局繪圖區(qū)域,可包含如下參數(shù):
num :設置圖像編號
figsize :設置圖像的寬度和高度,單位為英寸
facecolor :設置圖像背景顏色
dpi :設置繪圖對象的分辨率
edgecolor :設置圖像邊框顏色
例子1:
2.2 plt.subplot()
subplot () 用于全局繪圖區(qū)域中創(chuàng)建自繪圖區(qū)域,可包含如下參數(shù):
nrow:subplot 的行數(shù)
ncols :subplot 的列數(shù)
注意:使用 subplot 可規(guī)劃 figure 劃分為 N 個子圖,但每條 subplot 命令只能創(chuàng)建一個子圖。
例子2:
2.3 plt.axes()
plt.axes ( rect,axisbg = ‘w’ ) 創(chuàng)建一個坐標系風格的子繪圖區(qū)域。默認創(chuàng)建一個 subplot (111) 坐標系,參數(shù) rect = [ left,bottom,width,height ] 中4個變量中的范圍都是 [ 0 , 1 ],表示坐標系與全局繪圖區(qū)域的關系;axisbg 表示背景色,默認為白色 ’ white '。
例子3:
2.4 plt.subplots_adjust ()
**plt.subplots_adjust ()** 用于調(diào)整子繪圖區(qū)域的布局。總結(jié)
以上是生活随笔為你收集整理的matplotlib.pyplot 库(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: APIcloud开发——生成IOS系统测
- 下一篇: 小明加密通道进入_「成都全接触」最新!成