关于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获取CPU、内存和硬盘等windowns系统信息的2个例子
Apr 15 Python
Python socket.error: [Errno 98] Address already in use的原因和解决方法
Aug 25 Python
python实现ping的方法
Jul 06 Python
Python判断列表是否已排序的各种方法及其性能分析
Jun 20 Python
初学python的操作难点总结(新手必看篇)
Aug 03 Python
python 简单搭建阻塞式单进程,多进程,多线程服务的实例
Nov 01 Python
Python+selenium实现截图图片并保存截取的图片
Jan 05 Python
对python3 urllib包与http包的使用详解
May 10 Python
Python文件读写保存操作的示例代码
Sep 14 Python
pandas 将索引值相加的方法
Nov 15 Python
对python中字典keys,values,items的使用详解
Feb 03 Python
python语言是免费还是收费的?
Jun 15 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
对textarea框的代码调试,而且功能上使用非常方便,酷
2006/06/30 Javascript
JavaScript URL参数读取改进版
2009/01/16 Javascript
js实现屏蔽默认快捷键调用自定义事件示例
2013/06/18 Javascript
jQuery元素的隐藏与显示实例
2015/01/20 Javascript
javascript判断复选框是否选中的方法
2015/10/16 Javascript
使用jQuery的easydrag插件实现可拖动的DIV弹出框
2016/02/19 Javascript
Bootstrap源码解读标签、徽章、缩略图和警示框(8)
2016/12/26 Javascript
利用prop-types第三方库对组件的props中的变量进行类型检测
2017/05/02 Javascript
Vuex 单状态库与多模块状态库详解
2018/12/11 Javascript
Element input树型下拉框的实现代码
2018/12/21 Javascript
ES6知识点整理之函数对象参数默认值及其解构应用示例
2019/04/17 Javascript
javascript设计模式 ? 迭代器模式原理与用法实例分析
2020/04/17 Javascript
Openlayers实现扩散的动态点(水纹效果)
2020/08/17 Javascript
[02:16]DOTA2超级联赛专访Burning 逆袭需要抓住机会
2013/06/24 DOTA
跟老齐学Python之再深点,更懂list
2014/09/20 Python
在Python中定义和使用抽象类的方法
2016/06/30 Python
浅析python,PyCharm,Anaconda三者之间的关系
2019/11/27 Python
django 链接多个数据库 并使用原生sql实现
2020/03/28 Python
matlab中二维插值函数interp2的使用详解
2020/04/22 Python
在Keras中实现保存和加载权重及模型结构
2020/06/15 Python
python是怎么被发明的
2020/06/15 Python
matplotlib设置颜色、标记、线条,让你的图像更加丰富(推荐)
2020/09/25 Python
python 多线程中join()的作用
2020/10/29 Python
做一个能自适应高度的textarea的示例代码
2019/09/06 HTML / CSS
Woolworth官网:澳洲第一大超市
2017/06/25 全球购物
荷兰浴室和卫浴网上商店:Badkamerxxl.nl
2020/10/06 全球购物
remote接口和home接口主要作用
2013/05/15 面试题
化工专业应届生求职信
2013/11/08 职场文书
保护环境建议书
2014/03/12 职场文书
党员个人对照检查材料思想汇报
2014/09/16 职场文书
四风问题对照检查材料整改措施
2014/09/27 职场文书
幼儿教师年度个人总结
2015/02/05 职场文书
同意报考证明
2015/06/17 职场文书
Mysql systemctl start mysqld报错的问题解决
2021/06/03 MySQL
node.js使用express-fileupload中间件实现文件上传
2021/07/16 Javascript
一篇文章带你学习Mybatis-Plus(新手入门)
2021/08/02 Java/Android