博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python3绘图示例2(基于matplotlib:柱状图、分布图、三角图等)
阅读量:2242 次
发布时间:2019-05-09

本文共 2427 字,大约阅读时间需要 8 分钟。

#!/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()

转载于:https://www.cnblogs.com/NiceTime/p/10125213.html

你可能感兴趣的文章
Object中的getClass()返回的是当前运行的类
查看>>
加载驱动程序的方法
查看>>
深入理解java异常处理机制
查看>>
object类的基本方法
查看>>
回答阿里社招面试如何准备,顺便谈谈对于Java程序猿学习当中各个阶段的建议
查看>>
Dubbo分布式服务框架入门(附工程)
查看>>
两年Java开发工作经验面试总结
查看>>
作为Java面试官--谈谈一年来的面试总结
查看>>
两年Java程序员面试经
查看>>
面试心得与总结---BAT、网易、蘑菇街
查看>>
如何面试有2年java工作经验的应聘人员
查看>>
Java实现简单的递归操作
查看>>
面试Java程序员需具备的11个技能
查看>>
HashMap 和 HashTable 到底哪不同 ?
查看>>
Java实现简单的递归操作
查看>>
Struts2工作原理和执行流程图
查看>>
在线预览Word,Excel~
查看>>
hibernate延迟加载(get和load的区别)
查看>>
关于文件拷贝效率问题
查看>>
MyBatis分页插件PageHelper的使用
查看>>