#!/usr/bin/env python
# -*- coding:utf-8 -*- from matplotlib import pyplot as plt
import numpy as np
import pylab import os,sys,time,math,random # 图1-给已有的图加上刻度
file=r'D:\jmeter\jmeter3.2\data\Oracle数据库基础.png'
arr=np.array(file.getdata()).reshape(file.size[1],file.size[0],3) plt.gray()
plt.imshow(arr) plt.colorbar()
plt.show() # 图2-随机柱状图
SAMPLE_SIZE=100
random.seed()
real_rand_vars=[] real_rand_vars=[random.random() for val in range(SAMPLE_SIZE)]
pylab.hist(real_rand_vars,10) pylab.xlabel("number range")
pylab.ylabel("count")
pylab.show() # 图3-正太分布图
duration=100 # 中值
mean_inc=0.6 # 标准差
std_dev_inc=1.2 x=range(duration)
y=[]
price_today=0 for i in x:
next_delta=random.normalvariate(mean_inc,std_dev_inc)
price_today+=next_delta
y.append(price_today) pylab.plot(x,y)
pylab.title('test')
pylab.xlabel('time')
pylab.ylabel('value')
pylab.show() # 图4
SAMPLE_SIZE=1000
buckes=100 plt.figure()
plt.rcParams.update({'font.size':7}) # 子图1-随机分布 0~1
plt.subplot(621)
plt.xlabel('random1') res=[random.random() for _ in range(1,SAMPLE_SIZE)]
plt.hist(res,buckes) # 子图2-均匀分布
plt.subplot(622)
plt.xlabel('random2') a=1
b=SAMPLE_SIZE
res=[random.uniform(a,b) for _ in range(1,SAMPLE_SIZE)]
plt.hist(res,buckes) # 子图3-三角形分布
plt.subplot(623)
plt.xlabel('random3') low=1
high=SAMPLE_SIZE
res=[random.triangular(a,b) for _ in range(1,SAMPLE_SIZE)]
plt.hist(res,buckes) # 子图4-beta分布图
plt.subplot(624)
plt.xlabel('random4') alpha=1
beta=10
res = [random.betavariate(alpha,beta) for _ in range(1,SAMPLE_SIZE)]
plt.hist(res,buckes) # 子图5-指数分布图
plt.subplot(625)
plt.xlabel('random5')
lambd=1.0/((SAMPLE_SIZE+1)/2) res=[random.expovariate(lambd) for _ in range(1,SAMPLE_SIZE)]
plt.hist(res,buckes) # 子图6-gamma分布图
plt.subplot(626)
plt.xlabel('random6') alpha=1
beta=10
res = [random.gammavariate(alpha,beta) for _ in range(1,SAMPLE_SIZE)]
plt.hist(res,buckes) # 子图7-对数正太分布图
plt.subplot(627)
plt.xlabel('random7') # 中值
mu=1 # 标准差
sigma=0.5 res = [random.lognormvariate(mu,sigma) for _ in range(1,SAMPLE_SIZE)]
plt.hist(res,buckes) # 子图8-正太分布图
plt.subplot(628)
plt.xlabel('random8') # 中值
mu=1 # 标准差
sigma=0.5 res = [random.normalvariate(mu,sigma) for _ in range(1,SAMPLE_SIZE)]
plt.hist(res,buckes) # 子图9-帕累托分布图
plt.subplot(629)
plt.xlabel('random9') # 形状参数
alpha=1 res = [random.paretovariate(alpha) for _ in range(1,SAMPLE_SIZE)]
plt.hist(res,buckes) plt.tight_layout()
plt.show()

python3绘图示例2(基于matplotlib:柱状图、分布图、三角图等)的更多相关文章

  1. python3绘图示例6-2(基于matplotlib,绘图流程介绍及设置等)

    #!/usr/bin/env python# -*- coding:utf-8 -*- import os import numpy as npimport matplotlib as mpltfro ...

  2. python3绘图示例5(基于matplotlib:正弦图等)

    #!/usr/bin/env python# -*- coding:utf-8 -*- import numpy as npimport pylab as pyimport matplotlib as ...

  3. python3绘图示例4(基于matplotlib:箱线图、散点图等)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from matplotlib.pyplot import * x=[1,2,3,4]y=[5,4,3,2] # ...

  4. python3绘图示例1(基于matplotlib)

    #!/usr/bin/env python# -*- coding:utf-8 -*- import numpy as npimport matplotlib.pyplot as pltimport ...

  5. python3绘图示例6-1(基于matplotlib,绘图流程介绍及设置等)

    #!/usr/bin/env python# -*- coding:utf-8 -*- import os import pylab as pyimport numpy as npfrom matpl ...

  6. python3绘图示例3(基于matplotlib:折线图等)

    #!/usr/bin/env python# -*- coding:utf-8 -*-from pylab import *from numpy import *import numpy # 数据点图 ...

  7. Matplotlib常用绘图示例

    一.Matplotlib介绍 Matplotlib是一个Python的2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形.通过Matplotlib,开发者可以仅需要几行代码,便可 ...

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

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

  9. 基于matplotlib的数据可视化 -

    matplotlib.pyplot(as mp or as plt)提供基于python语言的绘图函数 引用方式: import matplotlib.pyplot as mp / as plt 本章 ...

随机推荐

  1. springboot整合mybatis,redis,代码(四)

    一 说明 这是spring整合redis注解开发的系类: 二 正文 在注解开发时候,会有这几个注解需要注意: 具体含义: 1.@Cacheable 可以标记在方法上,也可以标记在类上.当标记在方法上时 ...

  2. (转)TestNG框架提供两种传入参数的方法:

    1.从testng.xml传入参数. 如果参数是一些简单的值,可以直接在testng.xml中定义.这也是最常用的一种. 可以在测试用例中给参数一个默认值.这样,即使在xml文件中没有这个变量,你的测 ...

  3. ubuntu开机自启动服务管理

    安装sysv-rc-conf sudo apt-get install sysv-rc-conf 执行下面,查看服务情况 sudo sysv-rc-conf 启动服务有以下两种方式 update-rc ...

  4. css3文本域焦点烟花效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 【学习笔记】JavaScript的基础学习

    [学习笔记]JavaScript的基础学习 一 变量 1 变量命名规则 Camel 标记法 首字母是小写的,接下来的字母都以大写字符开头.例如: var myTestValue = 0, mySeco ...

  6. C语言标准库函数memcpy和memmove的区别以及内存重叠问题处理

    ①memcpy()和memmove()都是C语言中的标准库函数,定义在头文件string.h中,作用是拷贝一定长度的内存的内容,原型分别如下: void *memcpy(void *dst, cons ...

  7. spring boot 启动时运行代码(2)ApplicationListener

    项目概览: StepExecutor: @Component @Slf4j public class StepExecutor implements Runnable { @Autowired pri ...

  8. C++标准库vector及迭代器

    vector是同一种对象的集合,每个对象都有一个对应的整数索引值.和string对象一样,标准库将负责管理与存储元素相关的类存.引入头文件 #include<vector> 1.vecto ...

  9. 谷歌Chrome浏览器离线安装包

    下载地址(自选版本) 链接: https://pan.baidu.com/s/1_gVP32tBNTR0pHhQbbM8Iw 密码: rmak 有能力的可以自行到下方地址下载: 最新稳定版:https ...

  10. grunt 安装使用(一)

    grunt 依赖nodejs,所有在使用前确保你安装了nodejs,然后开始执行grunt命令. .安装node nodejs安装教程 安装完成后在命令行,执行命令: node  -v 出现版本信息, ...