关于python中plt.hist参数的使用详解


Posted in Python onNovember 28, 2019

如下所示:

matplotlib.pyplot.hist( 
  x, bins=10, range=None, normed=False,  
  weights=None, cumulative=False, bottom=None,  
  histtype=u'bar', align=u'mid', orientation=u'vertical',  
  rwidth=None, log=False, color=None, label=None, stacked=False,  
  hold=None, **kwargs)

x : (n,) array or sequence of (n,) arrays

这个参数是指定每个bin(箱子)分布的数据,对应x轴

bins : integer or array_like, optional

这个参数指定bin(箱子)的个数,也就是总共有几条条状图

normed : boolean, optional

If True, the first element of the return tuple will be the counts normalized to form a probability density, i.e.,n/(len(x)`dbin)

这个参数指定密度,也就是每个条状图的占比例比,默认为1

color : color or array_like of colors or None, optional

这个指定条状图的颜色

我们绘制一个10000个数据的分布条状图,共50份,以统计10000分的分布情况

""" 
  Demo of the histogram (hist) function with a few features. 
   
  In addition to the basic histogram, this demo shows a few optional features: 
   
    * Setting the number of data bins 
    * The ``normed`` flag, which normalizes bin heights so that the integral of 
     the histogram is 1. The resulting histogram is a probability density. 
    * Setting the face color of the bars 
    * Setting the opacity (alpha value). 
   
  """ 
  import numpy as np 
  import matplotlib.mlab as mlab 
  import matplotlib.pyplot as plt 
   
   
  # example data 
  mu = 100 # mean of distribution 
  sigma = 15 # standard deviation of distribution 
  x = mu + sigma * np.random.randn(10000) 
   
  num_bins = 50 
  # the histogram of the data 
  n, bins, patches = plt.hist(x, num_bins, normed=1, facecolor='blue', alpha=0.5) 
  # add a 'best fit' line 
  y = mlab.normpdf(bins, mu, sigma) 
  plt.plot(bins, y, 'r--') 
  plt.xlabel('Smarts') 
  plt.ylabel('Probability') 
  plt.title(r'Histogram of IQ: $\mu=100$, $\sigma=15$') 
   
  # Tweak spacing to prevent clipping of ylabel 
  plt.subplots_adjust(left=0.15) 
  plt.show()

关于python中plt.hist参数的使用详解

以上这篇关于python中plt.hist参数的使用详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python连接mysql实例分享
Oct 09 Python
深入理解python中的select模块
Apr 23 Python
python3基于OpenCV实现证件照背景替换
Jul 18 Python
Flask框架工厂函数用法实例分析
May 25 Python
numpy.where() 用法详解
May 27 Python
PHP统计代码行数的小代码
Sep 19 Python
使用python脚本自动创建pip.ini配置文件代码实例
Sep 20 Python
Python文本处理简单易懂方法解析
Dec 19 Python
python实现PCA降维的示例详解
Feb 24 Python
解决django接口无法通过ip进行访问的问题
Mar 27 Python
Python实现打包成库供别的模块调用
Jul 13 Python
使用numpngw和matplotlib生成png动画的示例代码
Jan 24 Python
python创建子类的方法分析
Nov 28 #Python
python 实现快速生成连续、随机字母列表
Nov 28 #Python
Python操作多维数组输出和矩阵运算示例
Nov 28 #Python
Python创建一个元素都为0的列表实例
Nov 28 #Python
Python使用matplotlib绘制Logistic曲线操作示例
Nov 28 #Python
Django框架反向解析操作详解
Nov 28 #Python
Django框架中间件定义与使用方法案例分析
Nov 28 #Python
You might like
水质对咖图啡风味的影响具体有哪些
2021/03/03 冲泡冲煮
在Windows中安装Apache2和PHP4的权威指南
2006/10/09 PHP
一致性哈希算法以及其PHP实现详细解析
2013/08/24 PHP
PHP实现的英文名字全拼随机排号脚本
2014/07/04 PHP
ThinkPHP权限认证Auth实例详解
2014/07/22 PHP
javascript实现数字+字母验证码的简单实例
2014/02/10 Javascript
AngularJS基础 ng-selected 指令简单示例
2016/08/03 Javascript
js实现登录注册框手机号和验证码校验(前端部分)
2017/09/28 Javascript
create-react-app安装出错问题解决方法
2018/09/04 Javascript
150行Node.js实现的dns代理工具
2019/08/02 Javascript
解决Vue项目中tff报错的问题
2020/10/21 Javascript
Python的Flask框架中实现分页功能的教程
2015/04/20 Python
Python实现多线程抓取网页功能实例详解
2017/06/08 Python
Python基于QRCode实现生成二维码的方法【下载,安装,调用等】
2017/07/11 Python
浅谈python和C语言混编的几种方式(推荐)
2017/09/27 Python
Python基于TCP实现会聊天的小机器人功能示例
2018/04/09 Python
解决python大批量读写.doc文件的问题
2018/05/08 Python
django+echart绘制曲线图的方法示例
2018/11/26 Python
jupyter notebook 参数传递给shell命令行实例
2020/04/10 Python
150行python代码实现贪吃蛇游戏
2020/04/24 Python
Python实现邮件发送的详细设置方法(遇到问题)
2021/01/18 Python
CSS3动画之流彩文字效果+图片模糊效果+边框伸展效果实现代码合集
2017/08/18 HTML / CSS
HTML5实现视频直播功能思路详解
2017/11/16 HTML / CSS
全球性的在线时尚男装零售商:boohooMAN
2016/12/17 全球购物
怎样声明子类
2013/07/02 面试题
口腔工艺技术专业毕业生自荐信
2013/09/27 职场文书
人代会标语
2014/06/30 职场文书
面试自我评价范文
2014/09/17 职场文书
简单租房协议书(范本)
2014/10/13 职场文书
2014年公司工作总结
2014/11/22 职场文书
技术支持岗位职责
2015/02/13 职场文书
2015年银行大堂经理工作总结
2015/04/24 职场文书
水浒传读书笔记
2015/06/25 职场文书
烈士陵园扫墓感想
2015/08/07 职场文书
五年级作文之成长
2019/09/16 职场文书
ORACLE数据库对long类型字段进行模糊匹配的解决思路
2021/04/07 Oracle