关于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中使用M2Crypto模块实现AES加密的教程
Apr 08 Python
编写Python脚本批量下载DesktopNexus壁纸的教程
May 06 Python
简单谈谈python中的多进程
Nov 06 Python
python基于itchat实现微信群消息同步机器人
Feb 27 Python
Python实现的根据文件名查找数据文件功能示例
May 02 Python
python多线程抽象编程模型详解
Mar 20 Python
使用python无账号无限制获取企查查信息的实例代码
Apr 17 Python
IntelliJ 中配置 Anaconda的过程图解
Jun 01 Python
使用SimpleITK读取和保存NIfTI/DICOM文件实例
Jul 01 Python
如何用python免费看美剧
Aug 11 Python
Python全局变量与global关键字常见错误解决方案
Oct 05 Python
Python中文分词库jieba(结巴分词)详细使用介绍
Apr 07 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命令空间namespace及use的用法小结
2017/11/27 PHP
Laravel多域名下字段验证的方法
2019/04/04 PHP
Javascript select控件操作大全(新增、修改、删除、选中、清空、判断存在等)
2008/12/19 Javascript
jquery 弹出层注册页面等(asp.net后台)
2010/06/17 Javascript
jQuery获取Select选择的Text和Value(详细汇总)
2013/01/25 Javascript
Js 获取Gridview选中行的内容操作步骤
2013/02/05 Javascript
Jquery实现网页跳转或用命令打开指定网页的解决方法
2013/07/09 Javascript
利用jQuary实现文字浮动提示效果示例代码
2013/12/26 Javascript
跟我学Nodejs(一)--- Node.js简介及安装开发环境
2014/05/20 NodeJs
angularjs中的单元测试实例
2014/12/06 Javascript
JS实用的动画弹出层效果实例
2015/05/05 Javascript
轻松实现javascript图片轮播特效
2016/01/13 Javascript
jQuery实现的指纹扫描效果实例(附演示与demo源码下载)
2016/01/26 Javascript
jQuery实现限制文本框的输入长度
2017/01/11 Javascript
JS 在数组指定位置插入/删除数据的方法
2017/01/12 Javascript
Angular表格神器ui-grid应用详解
2017/09/29 Javascript
解析vue data不可以使用箭头函数问题
2018/07/03 Javascript
微信小程序显示倒计时功能示例【测试可用】
2018/12/03 Javascript
Django1.7+python 2.78+pycharm配置mysql数据库教程
2014/11/18 Python
[原创]教女朋友学Python3(二)简单的输入输出及内置函数查看
2017/11/30 Python
python基于twisted框架编写简单聊天室
2018/01/02 Python
Numpy array数据的增、删、改、查实例
2018/06/04 Python
django从请求到响应的过程深入讲解
2018/08/01 Python
selenium在执行phantomjs的API并获取执行结果的方法
2018/12/17 Python
python全局变量引用与修改过程解析
2020/01/07 Python
CSS3 :not()选择器实现最后一行li去除某种css样式
2016/10/19 HTML / CSS
eBay美国官网:eBay.com
2020/10/24 全球购物
迪卡侬中国官网:Decathlon中国
2020/08/10 全球购物
个人素质的自我评价分享
2013/12/16 职场文书
运动会入场式解说词
2014/02/18 职场文书
投标保密承诺书
2014/05/19 职场文书
事业单位考核材料
2014/05/21 职场文书
公务员群众路线专题民主生活会发言材料
2014/09/17 职场文书
机关作风整顿个人整改措施2014
2014/09/17 职场文书
物业保洁员管理制度
2015/08/05 职场文书
Redis sentinel哨兵集群的实现步骤
2022/07/15 Redis