Python:matplotlib绘制直方图
使用hist方法来绘制直方图:
![](https://upload-images.jianshu.io/upload_images/13406307-10b316d01f631cec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/13406307-1b870e54a7f73daf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
绘制直方图,最主要的是一个数据集data和需要划分的区间数量bins,另外你也可以设置一些颜色、类型参数:
plt.hist(np.random.randn(1000), bins=30,normed=True, alpha=0.5, histtype='stepfilled', color='steelblue', edgecolor='none')
histtype直方图的类型,可以是'bar'、 'barstacked'、'step'和'stepfilled'。
有时候我们也会做一些直方对比图:
![](https://upload-images.jianshu.io/upload_images/13406307-63ee8261960123a9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/13406307-aadddbe0821fae14.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
除了一维的直方图,还可以使用hist2d方法绘制二维的直方图:
![](https://upload-images.jianshu.io/upload_images/13406307-b0ef34429e454dc4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/13406307-b01a860fed8fee9d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
hist2d是使用坐标轴正交的方块分割区域,还有一种常用的方式是正六边形也就是蜂窝形状的分割。Matplotlib提供的plt.hexbin就是满足这个需求的:
plt.hexbin(x,y,gridsize=30, cmap='Blues')
plt.colorbar(label='count in bin')
![](https://upload-images.jianshu.io/upload_images/13406307-a7cc8972c595fd5c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Python:matplotlib绘制直方图的更多相关文章
- NumPy使用 Matplotlib 绘制直方图
NumPy - 使用 Matplotlib 绘制直方图 NumPy 有一个numpy.histogram()函数,它是数据的频率分布的图形表示. 水平尺寸相等的矩形对应于类间隔,称为bin,变量hei ...
- python+matplotlib 绘制等高线
python+matplotlib 绘制等高线 步骤有七: 有一个m*n维的矩阵(data),其元素的值代表高度 构造两个向量:x(1*n)和y(1*m).这两个向量用来构造网格坐标矩阵(网格坐标矩阵 ...
- matplotlib绘制直方图【柱状图】
代码: def drawBar(): xticks = ['A', 'B', 'C', 'D', 'E']#每个柱的下标说明 gradeGroup = {'A':200,'B':250,'C':330 ...
- 关于matplotlib绘制直方图偏移的问题
在使用pyplot绘制直方图的时候我发现了一个问题,在给函数.hist()传参的时候,如果传入的组数不是刚刚好(就是说这个组数如果是使用(最大值-最小值)/组距计算出来,而这个数字不是整除得来而是取整 ...
- numpy和matplotlib绘制直方图
使用 Matplotlib Matplotlib 中有直方图绘制函数:matplotlib.pyplot.hist()它可以直接统计并绘制直方图.你应该使用函数 calcHist() 或 np.his ...
- 【转】使用Python matplotlib绘制股票走势图
转载出处 一.前言 matplotlib[1]是著名的python绘图库,它提供了一整套绘图API,十分适合交互式绘图.本人在工作过程中涉及到股票数据的处理如绘制K线等,因此将matplotlib的使 ...
- python pyqt绘制直方图
# -*- coding: utf-8 -*- """ In this example we draw two different kinds of histogram. ...
- python+matplotlib+绘制不同图标类型
#==================================================================#首先需要导入两个文件import matplotlib.pypl ...
- Python Matplotlib绘制气温图表
代码中数据从 www.wunderground.com/history/ 下载 #coding=utf-8 import csv from datetime import datetime from ...
随机推荐
- 【vue】vue +element 搭建项目,el-input 常用的验证
1.el-input 常用布局 <el-input class="filter-item dialog-search" size="small" @key ...
- Android APP性能测试笔记(二)
(5)FPS 每秒传输帧数(Frames Per Second),每秒钟帧数愈多,所显示的动作就会愈流畅,标准的fps是60 帧数就是在1秒钟时间里传输的图片的量,也可以理解为图形处理器每秒钟能够 ...
- fuser - 查看文件/网络端口等被什么进程占用
前提 linux环境下,当使用umount命令卸载挂载点时,会遇到“device is busy”提示,这时fuser就能查出谁在使用这个资源;当然umount –lf [挂载点] 也可以强制卸载 ...
- Spring(1)_Bean初始化
源码: 执行的代码 public static void main(String[] args) { ApplicationContext context=new ClassPathXmlApplic ...
- Ubuntu16.04之安装Nutch
1.下载Nutch wget http://mirrors.shu.edu.cn/apache/nutch/2.3.1/apache-nutch-2.3.1-src.zip 2.解压 unzip ap ...
- Python排序算法——选择排序
有趣的事,Python永远不会缺席! 如需转发,请注明出处:小婷儿的python https://www.cnblogs.com/xxtalhr/p/10787340.html 一.选择排序(Sele ...
- 进程同步控制(锁,信号量,事件), 进程通讯(队列和管道,生产者消费者模型) 数据共享(进程池和mutiprocess.Pool模块)
参考博客 https://www.cnblogs.com/xiao987334176/p/9025072.html#autoid-1-1-0 进程同步(multiprocess.Lock.Semaph ...
- C之attribute用法
GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和 ...
- CentOS 7 源码编译安装 Redis
1.下载源码并解压 wget http://download.redis.io/releases/redis-4.0.10.tar.gz tar -xzf redis-4.0.10.tar.gz cd ...
- CAP理论与分布式事务解决方案
微服务系统所设计的系统是分布式系统.分布式系统有一个著名的CAP理论,即同时满足"一致性""可用性"和"分区容错"是一件不可能的事.CAP理 ...