1、知识点

    1、通过数据和组距得到组数
2、使用plt.hist(数据,组数)绘制频数直方图;使用plt.hist(数据,组数,normed=True)绘制频率直方图
3、使用plt.xticks(a,b)设置x轴刻度。其中a表示刻度距离,b表示刻度描述(b可以不写)
4、plt.grid() 显示网格
5、plt.show()显示图像

2、案例

# coding=utf-8
from matplotlib import pyplot as plt
from matplotlib import font_manager a=[131, 98, 125, 131, 124, 139, 131, 117, 128, 108, 135, 138, 131, 102, 107, 114, 119, 128, 121, 142, 127, 130, 124, 101, 110, 116, 117, 110, 128, 128, 115, 99, 136, 126, 134, 95, 138, 117, 111,78, 132, 124, 113, 150, 110, 117, 86, 95, 144, 105, 126, 130,126, 130, 126, 116, 123, 106, 112, 138, 123, 86, 101, 99, 136,123, 117, 119, 105, 137, 123, 128, 125, 104, 109, 134, 125, 127,105, 120, 107, 129, 116, 108, 132, 103, 136, 118, 102, 120, 114,105, 115, 132, 145, 119, 121, 112, 139, 125, 138, 109, 132, 134,156, 106, 117, 127, 144, 139, 139, 119, 140, 83, 110, 102,123,107, 143, 115, 136, 118, 139, 123, 112, 118, 125, 109, 119, 133,112, 114, 122, 109, 106, 123, 116, 131, 127, 115, 118, 112, 135,115, 146, 137, 116, 103, 144, 83, 123, 111, 110, 111, 100, 154,136, 100, 118, 119, 133, 134, 106, 129, 126, 110, 111, 109, 141,120, 117, 106, 149, 122, 122, 110, 118, 127, 121, 114, 125, 126,114, 140, 103, 130, 141, 117, 106, 114, 121, 114, 133, 137, 92,121, 112, 146, 97, 137, 105, 98, 117, 112, 81, 97, 139, 113,134, 106, 144, 110, 137, 137, 111, 104, 117, 100, 111, 101, 110,105, 129, 137, 112, 120, 113, 133, 112, 83, 94, 146, 133, 101,131, 116, 111, 84, 137, 115, 122, 106, 144, 109, 123, 116, 111,111, 133, 150] plt.figure() #计算组数
d = 3
num_bins = (max(a)-min(a))//d #绘制频数直方图 ,normed=True绘制频率直方图
plt.hist(a,num_bins); #设置x轴刻度
plt.xticks(range(min(a),max(a)+d,d)) #显示网格
plt.grid() #展现图形
plt.show()

matplotlib之直方图的更多相关文章

  1. numpy和matplotlib绘制直方图

    使用 Matplotlib Matplotlib 中有直方图绘制函数:matplotlib.pyplot.hist()它可以直接统计并绘制直方图.你应该使用函数 calcHist() 或 np.his ...

  2. NumPy使用 Matplotlib 绘制直方图

    NumPy - 使用 Matplotlib 绘制直方图 NumPy 有一个numpy.histogram()函数,它是数据的频率分布的图形表示. 水平尺寸相等的矩形对应于类间隔,称为bin,变量hei ...

  3. matplotlib绘制直方图【柱状图】

    代码: def drawBar(): xticks = ['A', 'B', 'C', 'D', 'E']#每个柱的下标说明 gradeGroup = {'A':200,'B':250,'C':330 ...

  4. 关于matplotlib绘制直方图偏移的问题

    在使用pyplot绘制直方图的时候我发现了一个问题,在给函数.hist()传参的时候,如果传入的组数不是刚刚好(就是说这个组数如果是使用(最大值-最小值)/组距计算出来,而这个数字不是整除得来而是取整 ...

  5. Python:matplotlib绘制直方图

    使用hist方法来绘制直方图:     绘制直方图,最主要的是一个数据集data和需要划分的区间数量bins,另外你也可以设置一些颜色.类型参数: plt.hist(np.random.randn(1 ...

  6. Matplotlib学习---用matplotlib画直方图/密度图(histogram, density plot)

    直方图用于展示数据的分布情况,x轴是一个连续变量,y轴是该变量的频次. 下面利用Nathan Yau所著的<鲜活的数据:数据可视化指南>一书中的数据,学习画图. 数据地址:http://d ...

  7. 4.matplotlib绘制直方图

      # coding=utf-8 from matplotlib import pyplot as plt from matplotlib import font_manager a=[131, ...

  8. Python Numpy matplotlib Histograms 直方图

    import numpy as np import matplotlib.pyplot as plt mu,sigma = 2,0.5 v = np.random.normal(mu,sigma,10 ...

  9. Matplotlib学习---matplotlib的一些基本用法

    Matplotlib有两种接口,一种是matlab风格接口,一种是面向对象接口.在这里,统一使用面向对象接口.因为面向对象接口可以适应更复杂的场景,在多图之间进行切换将变得非常容易. 首先导入matp ...

随机推荐

  1. VToRay C-S config

    Server config: { "inbounds": [{ "port": 20000, //Server Listening Port "pro ...

  2. c++ 常用数据类型转换

    1.int型与string型的互相转换 int型转string型 void int2str(const int &int_temp,string &string_temp) { str ...

  3. 自己实现strcat函数

    问题:自己实现一个strcat_s函数,要和C语言库函数的strcat函数完成同样的功能. (1) 函数原型 char *strcat(char *dest, const char *src); (2 ...

  4. docker 运行centos显示连不上网络

    centos 7 docker 启动了一个web服务 但是启动时 报 WARNING: IPv4 forwarding is disabled. Networking will not work. 网 ...

  5. js去掉url后某参数【函数封装】

    function delParam(paramKey) { var url = window.location.href; //页面url var urlParam = window.location ...

  6. iOS 获取手机型号(已更新至iPhone11)

    + (NSString *)iphoneType {            //    需要导入头文件:#import <sys/utsname.h>        struct utsn ...

  7. web.xml中<welcome-file-list>标签不起作用

    之前也都提到过,web.xml会通过<servlet>和<servlet-mapping>来确定url和指定contoller文件,乃至于jsp页面的联系. 但是有一个< ...

  8. 【线段树哈希】「Balkan OI 2016」Haker

    1A海星 题目大意 给你一个长度为 $n$ ,由小写字母构成的字符串 $S$ 和 $Q$ 个操作,每个操作是以下 3 种之一: 1 x y k :询问当前字符串从位置 $x$ 到 $y$ 的子串与从位 ...

  9. loj2425 「NOIP2015」运输计划[二分答案+树上差分]

    看到题意最小化最长路径,显然二分答案,枚举链长度不超过$\text{mid}$,然后尝试检验.````` 检验是否存在这样一个边置为0后,全部链长$\le\text{mid}$,其最终目标就是.要让所 ...

  10. pycharm 怎么能像在命令行中输入参数进行调试

    pycharm中配置main参数 Run->Edit Configurations->Script Parames 把需要在xxx.py A B C 后面的参数输入到如下位置. 否则会报错 ...