关于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 ljust rjust center输出
Sep 06 Python
python使用beautifulsoup从爱奇艺网抓取视频播放
Jan 23 Python
Python实现比较两个文件夹中代码变化的方法
Jul 10 Python
在Python的Django框架中生成CSV文件的方法
Jul 22 Python
pycharm编写spark程序,导入pyspark包的3中实现方法
Aug 02 Python
Python pandas.DataFrame 找出有空值的行
Sep 09 Python
解决django model修改添加字段报错的问题
Nov 18 Python
基于pandas中expand的作用详解
Dec 17 Python
selenium 多窗口切换的实现(windows)
Jan 18 Python
详解Python利用configparser对配置文件进行读写操作
Nov 03 Python
解决Pytorch中关于model.eval的问题
May 22 Python
python实现双链表
May 25 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
Windows下IIS6/Apache2.2.4+MySQL5.2+PHP5.2.1安装配置方法
2007/05/03 PHP
php数组函数序列之array_search()- 按元素值返回键名
2011/11/04 PHP
php木马webshell扫描器代码
2012/01/25 PHP
PHP中使用Memache作为进程锁的操作类分享
2015/03/30 PHP
php写入、删除与复制文件的方法
2015/06/20 PHP
php简单实现文件或图片强制下载的方法
2016/12/06 PHP
基于JQuery的6个Tab选项卡插件
2010/09/03 Javascript
Document.location.href和.replace的区别示例介绍
2014/03/04 Javascript
javascript中Date对象的getDay方法使用指南
2014/12/22 Javascript
jQuery弹出层插件Lightbox_me使用指南
2015/04/21 Javascript
jQuery实现点击弹出背景变暗遮罩效果实例代码
2016/06/24 Javascript
Angularjs的$http异步删除数据详解及实例
2017/07/27 Javascript
vue.js评论发布信息可插入QQ表情功能
2017/08/08 Javascript
使用VUE+iView+.Net Core上传图片的方法示例
2019/01/04 Javascript
vue指令之表单控件绑定v-model v-model与v-bind结合使用
2019/04/17 Javascript
nodejs nedb 封装库与使用方法示例
2020/02/06 NodeJs
jQuery实现鼠标放置名字上显示详细内容气泡提示框效果的方法分析
2020/04/04 jQuery
部署vue+Springboot前后端分离项目的步骤实现
2020/05/31 Javascript
python基础教程之python消息摘要算法使用示例
2014/02/10 Python
Python的SQLalchemy模块连接与操作MySQL的基础示例
2016/07/11 Python
TensorFlow实现创建分类器
2018/02/06 Python
Python实现利用163邮箱远程关电脑脚本
2018/02/22 Python
Python实现k-means算法
2018/02/23 Python
python批量查询、汉字去重处理CSV文件
2018/05/31 Python
django使用xadmin的全局配置详解
2019/11/15 Python
Hotter Shoes美国官网:英国最受欢迎的舒适鞋
2018/08/02 全球购物
牧马人澳大利亚官网:Wrangler澳大利亚
2019/10/08 全球购物
面向对象编程是如何提高软件开发水平的
2014/05/06 面试题
关于递归的一道.NET面试题
2013/05/12 面试题
《理想》教学反思
2014/02/17 职场文书
护理专科毕业生自荐书范文
2014/02/19 职场文书
医院保洁员岗位职责
2015/02/13 职场文书
幼儿园卫生保健制度
2015/08/05 职场文书
2019年妇科护士的自我鉴定(3篇)
2019/09/26 职场文书
Nginx的rewrite模块详解
2021/03/31 Servers
Html5同时支持多端sdk的小技巧
2021/11/17 HTML / CSS