关于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分割TXT文件成4K的TXT文件
May 23 Python
Python之re操作方法(详解)
Jun 14 Python
微信跳一跳python辅助脚本(总结)
Jan 11 Python
Python实现爬虫从网络上下载文档的实例代码
Jun 13 Python
解决Django生产环境无法加载静态文件问题的解决
Apr 23 Python
基于Python打造账号共享浏览器功能
May 30 Python
关于不懂Chromedriver如何配置环境变量问题解决方法
Jun 12 Python
Golang GBK转UTF-8的例子
Aug 26 Python
python使用梯度下降和牛顿法寻找Rosenbrock函数最小值实例
Apr 02 Python
Pycharm操作Git及GitHub的步骤详解
Oct 27 Python
基于Python组装jmx并调用JMeter实现压力测试
Nov 03 Python
详解Python为什么不用设计模式
Jun 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
PHP校验ISBN码的函数代码
2011/01/17 PHP
PHP 获取远程网页内容的代码(fopen,curl已测)
2011/06/06 PHP
自己写的兼容低于PHP 5.5版本的array_column()函数
2014/10/24 PHP
php文件缓存类汇总
2014/11/21 PHP
Laravel框架基于中间件实现禁止未登录用户访问页面功能示例
2019/01/17 PHP
laravel-admin 管理平台获取当前登陆用户信息的例子
2019/10/08 PHP
PHP用swoole+websocket和redis实现web一对一聊天
2019/11/05 PHP
phpstudy后门rce批量利用脚本的实现
2019/12/12 PHP
Laravel框架处理用户的请求操作详解
2019/12/20 PHP
清空上传控件input file的值
2010/07/03 Javascript
JavaScript中为元素加上name属性的方法
2011/05/09 Javascript
PHP中CURL的几个经典应用实例
2015/01/23 Javascript
基于JS实现数字+字母+中文的混合排序方法
2016/06/06 Javascript
JS小数转换为整数的方法分析
2017/01/07 Javascript
使用javaScript实现鼠标拖拽事件
2020/04/03 Javascript
Router解决跨模块下的页面跳转示例
2018/01/11 Javascript
Js逆向实现滑动验证码图片还原的示例代码
2020/03/10 Javascript
解决vue-loader加载不上的问题
2020/10/21 Javascript
[01:59]DOTA2首部纪录片《Free to play》预告片
2014/03/12 DOTA
[44:50]2018DOTA2亚洲邀请赛 4.1 小组赛 A组 TNC vs VG
2018/04/02 DOTA
Python简单读取json文件功能示例
2017/11/30 Python
python的pyecharts绘制各种图表详细(附代码)
2019/11/11 Python
python二元表达式用法
2019/12/04 Python
python重要函数eval多种用法解析
2020/01/14 Python
pytorch方法测试详解——归一化(BatchNorm2d)
2020/01/15 Python
python matplotlib包图像配色方案分享
2020/03/14 Python
Smashbox官网:美国知名彩妆品牌
2017/01/05 全球购物
英国网上购买门:Direct Doors
2018/06/07 全球购物
LN-CC中国:高端男装和女装的奢侈时尚目的地
2019/09/14 全球购物
Abbott Lyon官网:女士手表、珠宝及配件
2020/12/26 全球购物
《鲁班和橹板》教学反思
2014/04/27 职场文书
知识竞赛拉拉队口号
2014/06/16 职场文书
校园学雷锋广播稿
2014/10/08 职场文书
怀孕辞职信怎么写
2015/02/28 职场文书
紧急迫降观后感
2015/06/15 职场文书
2015年高中生国庆节演讲稿
2015/07/30 职场文书