- NumPy环境安装配置
- NumPy Ndarray对象
- NumPy数据类型
- NumPy数组属性
- NumPy数组创建例程
- NumPy来自现有数据的数组
- NumPy来自数值范围的数组
- NumPy切片和索引
- NumPy高级索引
- NumPy广播
- NumPy在数组上的迭代
- NumPy数组操作
- NumPy位操作
- NumPy字符串函数
- NumPy数学算数函数
- NumPy算数运算
- NumPy统计函数
- NumPy排序、搜索和计数函数
- NumPy字节交换
- NumPy副本和视图
- NumPy矩阵库
- NumPy线性代数
- NumPy Matplotlib库
- NumPy使用 Matplotlib 绘制直方图
- NumPy IO文件操作
NumPy使用 Matplotlib 绘制直方图
NumPy - 使用 Matplotlib 绘制直方图
NumPy 有一个numpy.histogram()
函数,它是数据的频率分布的图形表示。 水平尺寸相等的矩形对应于类间隔,称为bin
,变量height
对应于频率。
numpy.histogram()" class="reference-link">numpy.histogram()
numpy.histogram()
函数将输入数组和bin
作为两个参数。 bin
数组中的连续元素用作每个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()" class="reference-link">plt()
Matplotlib 可以将直方图的数字表示转换为图形。 pyplot
子模块的plt()
函数将包含数据和bin
数组的数组作为参数,并转换为直方图。
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()
输出如下:
下一篇:NumPy IO文件操作
关注微信小程序
扫描二维码
程序员编程王