关于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发送邮件接收邮件示例分享
Jan 21 Python
python网络编程学习笔记(八):XML生成与解析(DOM、ElementTree)
Jun 09 Python
使用Python脚本在Linux下实现部分Bash Shell的教程
Apr 17 Python
Python之re操作方法(详解)
Jun 14 Python
python中文乱码不着急,先看懂字节和字符
Dec 20 Python
python xlsxwriter库生成图表的应用示例
Mar 16 Python
python 寻找list中最大元素对应的索引方法
Jun 28 Python
Python依赖包整体迁移方法详解
Aug 15 Python
python实现简单飞行棋
Feb 06 Python
python 解决Fatal error in launcher:错误问题
May 21 Python
用OpenCV进行年龄和性别检测的实现示例
Jan 29 Python
如何在python中实现ECDSA你知道吗
Nov 23 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中将ip地址转成十进制数的两种实用方法
2013/08/15 PHP
php实现图形显示Ip地址的代码及注释
2014/01/20 PHP
php实现事件监听与触发的方法
2014/11/21 PHP
Symfony2安装的方法(2种方法)
2016/02/04 PHP
PHP去除空数组且数组键名重置的讲解
2019/02/28 PHP
php实现快速对二维数组某一列进行组装的方法小结
2019/12/04 PHP
jquery中$.post()方法的简单实例
2014/02/04 Javascript
jquery队列queue与原生模仿其实现方法分享
2014/03/25 Javascript
jQuery控制TR显示隐藏的三种常用方法
2014/08/21 Javascript
jQuery实现输入框下拉列表树插件特效代码分享
2015/08/27 Javascript
JavaScript对象数组如何按指定属性和排序方向进行排序
2016/06/15 Javascript
微信小程序(应用号)简单实例应用及实例详解
2016/09/26 Javascript
微信小程序 实战实例开发流程详细介绍
2017/01/05 Javascript
浅谈angularjs $http提交数据探索
2017/01/20 Javascript
vue元素实现动画过渡效果
2017/07/01 Javascript
vuex入门最详细整理
2020/03/04 Javascript
Vue中的this.$options.data()和this.$data用法说明
2020/07/26 Javascript
python实现提取百度搜索结果的方法
2015/05/19 Python
Python统计日志中每个IP出现次数的方法
2015/07/06 Python
python 网络爬虫初级实现代码
2016/02/27 Python
Python开发的HTTP库requests详解
2017/08/29 Python
wxPython实现整点报时
2019/11/18 Python
基于TensorBoard中graph模块图结构分析
2020/02/15 Python
python之MSE、MAE、RMSE的使用
2020/02/24 Python
用60行代码实现Python自动抢微信红包
2021/02/04 Python
Python实现简单的2048小游戏
2021/03/01 Python
利用HTML5实现使用按钮控制背景音乐开关
2015/09/21 HTML / CSS
如何在Canvas中添加事件的方法示例
2019/05/21 HTML / CSS
澳大利亚电商Catch新西兰站:Catch.co.nz
2020/05/30 全球购物
SQL注入攻击的种类有哪些
2013/12/30 面试题
实习期自我鉴定
2013/10/11 职场文书
车间统计员岗位职责
2014/01/05 职场文书
2014年小学生迎国庆65周年演讲稿
2014/09/27 职场文书
2015年大学学生会工作总结
2015/05/13 职场文书
2015年暑期实践报告范文
2015/07/13 职场文书
校园开放日新闻稿
2015/07/17 职场文书