关于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的迭代器与生成器实例详解
Jul 16 Python
python版本的读写锁操作方法
Apr 25 Python
Python实现的手机号归属地相关信息查询功能示例
Jun 08 Python
Python基于回溯法子集树模板解决选排问题示例
Sep 07 Python
python3+PyQt5+Qt Designer实现堆叠窗口部件
Apr 20 Python
Python之list对应元素求和的方法
Jun 28 Python
python 判断矩阵中每行非零个数的方法
Jan 26 Python
django框架模板中定义变量(set variable in django template)的方法分析
Jun 24 Python
python+pygame实现坦克大战
Sep 10 Python
python实现文件批量编码转换及注意事项
Oct 14 Python
python opencv实现gif图片分解的示例代码
Dec 13 Python
python如何快速生成时间戳
Jul 21 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
推荐文章系统(一)
2006/10/09 PHP
用缓存实现静态页面的测试
2006/12/06 PHP
php flush类输出缓冲剖析
2008/10/19 PHP
PHP header()函数使用详细(301、404等错误设置)
2013/04/17 PHP
php使用curl访问https示例分享
2014/01/17 PHP
PHP常量使用的几个需要注意的地方(谨慎使用PHP中的常量)
2014/09/12 PHP
php基于CodeIgniter实现图片上传、剪切功能
2016/05/14 PHP
CI框架AR数据库操作常用函数总结
2016/11/21 PHP
PHP检查URL包含特定字符串实例方法
2019/02/11 PHP
javascript中使用css需要注意的地方小结
2010/09/01 Javascript
一款Jquery 分页插件的改造方法(服务器端分页)
2011/07/11 Javascript
THREE.JS入门教程(2)着色器-上
2013/01/24 Javascript
javascript实现跳转菜单的具体方法
2013/07/05 Javascript
JS获取几种URL地址的方法小结
2014/02/26 Javascript
javascript 实现 原路返回
2015/01/21 Javascript
原创jQuery弹出层插件分享
2015/04/02 Javascript
AngularJS基础 ng-open 指令简单实例
2016/08/02 Javascript
Bootstrap中定制LESS-颜色及导航条(推荐)
2016/11/21 Javascript
微信小程序 获取session_key和openid的实例
2017/08/17 Javascript
如何构建 vue-ssr 项目的方法步骤
2020/08/04 Javascript
python多线程编程方式分析示例详解
2013/12/06 Python
在Python中使用swapCase()方法转换大小写的教程
2015/05/20 Python
Python计算已经过去多少个周末的方法
2015/07/25 Python
Django Web开发中django-debug-toolbar的配置以及使用
2018/05/06 Python
Python读取本地文件并解析网页元素的方法
2018/05/21 Python
详解python执行shell脚本创建用户及相关操作
2019/04/11 Python
flask利用flask-wtf验证上传的文件的方法
2020/01/17 Python
Python decorator拦截器代码实例解析
2020/04/04 Python
python如何编写win程序
2020/06/08 Python
Desigual美国官方网站:西班牙服装品牌
2019/03/29 全球购物
在校生钳工实习自我鉴定
2013/09/19 职场文书
中国梦读书活动总结
2014/07/10 职场文书
2014年依法行政工作总结
2014/11/19 职场文书
亲戚关系证明
2015/06/24 职场文书
MYSQL主从数据库同步备份配置的方法
2021/05/26 MySQL
MySQL基础快速入门知识总结(附思维导图)
2021/09/25 MySQL