目录

[TOC]

前言

今天我们学习的是直方图,导入的函数是:

plt.hist(x=x, bins=10) 与plt.hist2D(x=x, y=y)

(一)直方图

(1)说明:

pyplot.``hist(x, bins=None, density=None,……*kwargs)

常见的参数属性

具体参考:官网说明文档

属性 说明 类型
x 数据 数值类型
bins 条形数 int
color 颜色 "r","g","y","c"
density 是否以密度的形式显示 bool
range x轴的范围 数值元组(起,终)
bottom y轴的起始位置 数值类型
histtype 线条的类型 "bar":方形,"barstacked":柱形,<br />"step":"未填充线条"<br />"stepfilled":"填充线条"
align 对齐方式 "left":左,"mid":中间,"right":右
orientation orientation "horizontal":水平,"vertical":垂直
log 单位是否以科学计术法 bool

(2)源代码:

# 导入模块import matplotlib.pyplot as pltimport numpy as np# 数据mu = 100  # 均值sigma = 20  # 方差# 2000个数据x = mu + sigma*np.random.randn(2000)# 画图 bins:条形的个数, normed:是否标准化plt.hist(x=x, bins=10)# 展示plt.show()

(3)输出效果:

默认:y轴是个数

4.6Python数据处理篇之Matplotlib系列(六)—plt.hist()与plt.hist2d()直方图插图
01.png

改:plt.hist(x=x, bins=10, density=True)

y轴是频率

4.6Python数据处理篇之Matplotlib系列(六)—plt.hist()与plt.hist2d()直方图插图1
02.png

(二)双直方图

(1)说明:

pyplot.``hist2d(x, y, bins=10, **kwargs)

常见的参数属性

具体参考:官网说明文档

x x坐标
y y坐标
bins 横竖分为几条

(2)源代码:

# 导入模块import matplotlib.pyplot as pltimport numpy as np# 数据x = np.random.randn(1000)+2y = np.random.randn(1000)+3# 画图plt.hist2d(x=x, y=y, bins=30)# 展示plt.show()

(3)输出效果:

4.6Python数据处理篇之Matplotlib系列(六)—plt.hist()与plt.hist2d()直方图插图2
03.png

作者:Mark

日期:2019/02/13 周三

文章转载于:https://www.jianshu.com/p/273e28cafe85

原著是一个有趣的人,若有侵权,请通知删除

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《4.6Python数据处理篇之Matplotlib系列(六)—plt.hist()与plt.hist2d()直方图
   

还没有人抢沙发呢~