# _*_ coding: gbk _*_
# @Author: Wonde
# bar 直方图 import matplotlib.pyplot as plt # 绘图
from matplotlib.font_manager import FontProperties # 管理字体 font = FontProperties(fname=r'STLITI.TTF') # 设置字体 设置路径即可
plt.style.use('ggplot') # 样式可选,默认ggplot和classic
# print(plt.style.available) #查看可以使用的背景样式
classes = ['class1', 'class2', 'class3', 'class4'] # x轴数据
studentnum = [11, 21, 33, 25] # y轴数据
classes_index = range(len(classes)) # 传一个可迭代对象range是一个可迭代对象,目的是为了让非数字的X轴均匀分布,通过索引实现
#画布设计
fig = plt.figure() #实例化一个对象
ax1 = fig.add_subplot(1, 1, 1) # 将一个画布分为几(1)行(1)列以及选定第(1)张add_subplot(1, 1, 1) ax1.bar(classes_index, studentnum) # 设置一些参数
# def bar(self, x, height, width=0.8, bottom=None, *, align="center",**kwargs):
# 设置刻度值的显示位置
ax1.xaxis.set_ticks_position('bottom') # 刻度 x的刻度在底部,y的刻度在左边
ax1.yaxis.set_ticks_position('left') #设置X轴的刻度和数据,X轴因为不是具体数据,故用他所在的数组位置进行等差取值。
plt.xticks(classes_index, classes, rotation=0, fontsize=12, FontProperties=font) # 设置x和y轴以及标题栏的名字
plt.xlabel('班级', FontProperties=font, Fontsize=15)
plt.ylabel('学生人数', FontProperties=font, Fontsize=15)
plt.title('班级----学生人数', FontProperties=font, Fontsize=19)
plt.show()

****************************************************************************************************************************************************

# _*_ coding: gbk _*_
# @Author: Wonde
# bar 直方图 import matplotlib.pyplot as plt # 绘图
from matplotlib.font_manager import FontProperties # 管理字体 font = FontProperties(fname=r'STLITI.TTF') # 设置字体 设置路径即可
plt.style.use('ggplot') # 样式可选,默认ggplot和classic
# print(plt.style.available) #查看可以使用的背景样式
classes = ['class1', 'class2', 'class3', 'class4'] # x轴数据
studentnum = [11, 21, 33, 25] # y轴数据
classes_index = range(len(classes)) # 传一个可迭代对象range是一个可迭代对象
#画布设计
fig = plt.figure() #实例化一个对象
ax1 = fig.add_subplot(1, 1, 1) # 将一个画布分为几(1)行(1)列以及选定第(1)张add_subplot(1, 1, 1) ax1.barh( classes_index, studentnum) # 设置一些参数
# def barh(self, y, width, height=0.8, left=None, *, align="center",**kwargs):
# 设置刻度值的显示位置
ax1.xaxis.set_ticks_position('bottom') # 刻度 x的刻度在底部,y的刻度在左边
ax1.yaxis.set_ticks_position('left') # yticks设置y轴的刻度值 和数据,此时Y轴是班级,不是一个具体数值,所以需要用索引来做均分间隔。
plt.yticks(classes_index, classes, rotation=0, fontsize=12, FontProperties=font) # 设置x和y轴以及标题栏的名字
plt.xlabel('学生人数', FontProperties=font, Fontsize=15)
plt.ylabel('班级', FontProperties=font, Fontsize=15)
plt.title('班级----学生人数', FontProperties=font, Fontsize=19)
plt.show()

  

  重在理解!!!

高斯分布,又称为正态分布。秘籍的直方图可以绘制出高斯分布图

# _*_ coding: gbk _*_
# @Author: Wonder
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties font = FontProperties(fname='simhei.ttf')
plt.style.use('ggplot')
num1, num2, sigama = , ,
# 构造符合均值为20的正态分布,以及均值为50的正态分布。
x1 = num1 + sigama * np.random.randn() # 10000为构造随机数的个数
x2 = num2 + sigama * np.random.randn() fig = plt.figure() # 初始化画板
ax1 = fig.add_subplot(, , )
ax1.hist(x1, bins=, color='yellow') # bins=50表示分成50份,即会有50个直方图组成正态分布大图
ax2 = fig.add_subplot() ax2.hist(x2, bins=, color='green') fig.suptitle('两个图在一起', fontproperties=font, fontweight='bold',
fontsize=) # fontweight为字体粗细,bold为粗体,fontproperties字体属性
ax1.set_title('均值为20的正态分布图', fontproperties=font)
ax2.set_title('均值为50的正态分布图', fontproperties=font)
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 柱状图、饼图;直方图、盒图

    #-*- coding: utf-8 -*- import matplotlib.pyplot as plt import numpy as np import matplotlib as mpl m ...

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

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

  5. matplotlib柱状图、面积图、直方图、散点图、极坐标图、箱型图

    一.柱状图 1.通过obj.plot() 柱状图用bar表示,可通过obj.plot(kind='bar')或者obj.plot.bar()生成:在柱状图中添加参数stacked=True,会形成堆叠 ...

  6. 【Python】模块学习之matplotlib柱状图、饼状图、动态图及解决中文显示问题

    前言 众所周知,通过数据绘图,我们可以将枯燥的数字转换成容易被人们接受的图表,从而让人留下更加深刻的印象.而大多数编程语言都有自己的绘图工具,matplotlib就是基于Python的绘图工具包,使用 ...

  7. matplotlib柱状图-【老鱼学matplotlib】

    柱状图在平常的图表中是非常常用的图,本节我们来看下如何来显示柱状图. 代码为: import numpy as np import pandas as pd import matplotlib.pyp ...

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

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

  9. Python:matplotlib绘制直方图

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

随机推荐

  1. 通过java api 读取sql 中数据(查询)

    配置文件:dbconfig.properties 里面的数据 jdbc.url.jwhat=jdbc\:mysql\://ip\:3306/laibadev?useUnicode\=true& ...

  2. &与&&,|与||的区别

    今天在做leetcode的时候,遇到了运算符的不同而导致结果不一致的问题.记录一下提醒自己 中文名称与英文名称 &:按位与(Bitwise and) &&:逻辑与(logica ...

  3. spring Aop设计原理

    转载至:https://blog.csdn.net/luanlouis/article/details/51095702 0.前言 Spring 提供了AOP(Aspect Oriented Prog ...

  4. what codes does sudo command do in Linux?

    sometime, to make your change of configuration file be effective to web application, we have to rest ...

  5. keepAlived主备及双主

    nginx用默认配置即可 1.主备配置 1.主keepAlived配置 vrrp_instance VI_1 { state MASTER #主备区分 interface eth0 virtual_r ...

  6. Spark Streaming设计

  7. Linux 进程间通信 无名管道(pipe)

    无名管道: 1)只能用于具有亲缘关系的进程之间的通信(无名管道是某一个进程创建的,不像普通文件有路径,在文件系统中是不可见的,其他进程要想打开,只能通过继承的方式去打开) 2)半双工的通信模式,具有固 ...

  8. cross compile 交叉编译 ffmpeg

    ffmpeg 支持各种压缩格式的视频解码库,经常出现在各种播放器中,交叉编译也是一项麻烦的事情. 1. 下载ffmpeg 源码包   http://ffmpeg.org/releases/ffmpeg ...

  9. wget 下载文件

    # -c 继续执行上次终端的任务# --http-user http用户名# --http-passwd http密码# --no-check-certificate 不检查ssl/tsl证书. wg ...

  10. vue 外卖app(2) stylus

    1.安装 npm  install stylus   stylus-loader  --save-dev 安装成功 2.编写样式 <style  lang="stylus" ...