关于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通过openpyxl生成Excel文件的方法
May 12 Python
python发送邮件功能实现代码
Jul 15 Python
Python爬虫代理IP池实现方法
Jan 05 Python
用python实现百度翻译的示例代码
Mar 09 Python
详解PyCharm配置Anaconda的艰难心路历程
Aug 13 Python
用Python+OpenCV对比图像质量的几种方法
Jul 15 Python
Python使用Pandas对csv文件进行数据处理的方法
Aug 01 Python
用什么库写 Python 命令行程序(示例代码详解)
Feb 20 Python
在pycharm中使用matplotlib.pyplot 绘图时报错的解决
Jun 01 Python
keras:model.compile损失函数的用法
Jul 01 Python
如何将Pycharm中调整字体大小的方式设置为"ctrl+鼠标滚轮上下滑"
Nov 17 Python
教你使用Pandas直接核算Excel中快递费用
May 12 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中file_get_contents高?用法实例
2014/09/24 PHP
android上传图片到PHP的过程详解
2015/08/03 PHP
PHP添加图片水印、压缩、剪切的封装类
2015/08/17 PHP
PHP简单读取PDF页数的实现方法
2016/07/21 PHP
PHP实现按之字形顺序打印二叉树的方法
2018/01/16 PHP
Add a Picture to a Microsoft Word Document
2007/06/15 Javascript
jqPlot jquery的页面图表绘制工具
2009/07/25 Javascript
Javascript 获取链接(url)参数的方法[正则与截取字符串]
2010/02/09 Javascript
jQuery 处理表单元素的代码
2010/02/15 Javascript
使用JavaScript 实现对象 匀速/变速运动的方法
2013/05/08 Javascript
浅谈vue2 单页面如何设置网页title
2017/11/08 Javascript
对Vue table 动态表格td可编辑的方法详解
2018/08/28 Javascript
使用electron将vue-cli项目打包成exe的方法
2018/09/29 Javascript
js时间转换毫秒的实例代码
2019/08/21 Javascript
Python base64编码解码实例
2015/06/21 Python
python实现报表自动化详解
2017/11/16 Python
python使用xpath中遇到:到底是什么?
2018/01/04 Python
python实现校园网自动登录的示例讲解
2018/04/22 Python
python 定时任务去检测服务器端口是否通的实例
2019/01/26 Python
Python切片操作去除字符串首尾的空格
2019/04/22 Python
Python深拷贝与浅拷贝用法实例分析
2019/05/05 Python
Django使用uwsgi部署时的配置以及django日志文件的处理方法
2019/08/30 Python
利用Vscode进行Python开发环境配置的步骤
2020/06/22 Python
css3实现一款模仿iphone样式的注册表单
2013/03/20 HTML / CSS
LACOSTE波兰官网:Polo衫、服装和鞋类
2020/09/29 全球购物
super()与this()的区别
2016/01/17 面试题
会计电算化专业毕业生自荐信
2013/12/20 职场文书
小学生家长评语大全
2014/02/10 职场文书
教师节商场活动方案
2014/02/13 职场文书
《夸父追日》教学反思
2014/02/26 职场文书
人力资源主管的岗位职责
2014/03/15 职场文书
绿色出行口号
2014/06/18 职场文书
先进党支部事迹材料
2014/12/24 职场文书
大学学生个人总结
2015/02/15 职场文书
婚宴父母致辞
2015/07/27 职场文书
Python Pytorch查询图像的特征从集合或数据库中查找图像
2022/04/09 Python