鍍金池/ 教程/ 數(shù)據(jù)分析&挖掘/ NumPy使用 Matplotlib 繪制直方圖
NumPy位操作
NumPy數(shù)學算數(shù)函數(shù)
NumPy高級索引
NumPy環(huán)境安裝配置
NumPy IO文件操作
NumPy字符串函數(shù)
NumPy切片和索引
NumPy統(tǒng)計函數(shù)
NumPy矩陣庫
NumPy數(shù)組創(chuàng)建例程
NumPy線性代數(shù)
NumPy Matplotlib庫
NumPy教程
NumPy排序、搜索和計數(shù)函數(shù)
NumPy字節(jié)交換
NumPy Ndarray對象
NumPy數(shù)組操作
NumPy使用 Matplotlib 繪制直方圖
NumPy數(shù)組屬性
NumPy廣播
NumPy來自現(xiàn)有數(shù)據(jù)的數(shù)組
NumPy副本和視圖
NumPy在數(shù)組上的迭代
NumPy來自數(shù)值范圍的數(shù)組
NumPy算數(shù)運算
NumPy數(shù)據(jù)類型

NumPy使用 Matplotlib 繪制直方圖

NumPy - 使用 Matplotlib 繪制直方圖

NumPy 有一個numpy.histogram()函數(shù),它是數(shù)據(jù)的頻率分布的圖形表示。 水平尺寸相等的矩形對應(yīng)于類間隔,稱為bin,變量height對應(yīng)于頻率。

numpy.histogram()

numpy.histogram()函數(shù)將輸入數(shù)組和bin作為兩個參數(shù)。 bin數(shù)組中的連續(xù)元素用作每個bin的邊界。

import numpy as np 

a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27]) ]
np.histogram(a,bins =  [0,20,40,60,80,100]) 
hist,bins = np.histogram(a,bins =  [0,20,40,60,80,100])  
print hist 
print bins

輸出如下:

[3 4 5 2 1]
[0 20 40 60 80 100]

plt()

Matplotlib 可以將直方圖的數(shù)字表示轉(zhuǎn)換為圖形。 pyplot子模塊的plt()函數(shù)將包含數(shù)據(jù)和bin數(shù)組的數(shù)組作為參數(shù),并轉(zhuǎn)換為直方圖。

from matplotlib import pyplot as plt 
import numpy as np  

a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27]) 
plt.hist(a, bins =  [0,20,40,60,80,100]) 
plt.title("histogram") 
plt.show()

輸出如下: