python3绘图示例2(基于matplotlib:柱状图、分布图、三角图等)

#!/usr/bin/env python# -*- coding:utf-8 -*-

from matplotlib import pyplot as pltimport numpy as npimport 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=100random.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()

# 图4SAMPLE_SIZE=1000buckes=100

plt.figure()plt.rcParams.update({‘font.size‘:7})

# 子图1-随机分布 0~1plt.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=1b=SAMPLE_SIZEres=[random.uniform(a,b) for _ in range(1,SAMPLE_SIZE)]plt.hist(res,buckes)

# 子图3-三角形分布plt.subplot(623)plt.xlabel(‘random3‘)

low=1high=SAMPLE_SIZEres=[random.triangular(a,b) for _ in range(1,SAMPLE_SIZE)]plt.hist(res,buckes)

# 子图4-beta分布图plt.subplot(624)plt.xlabel(‘random4‘)

alpha=1beta=10res = [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=1beta=10res = [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

时间: 2024-08-29 17:38:26

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

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

#!/usr/bin/env python# -*- coding:utf-8 -*- from matplotlib.pyplot import * x=[1,2,3,4]y=[5,4,3,2] # 创建新图标figure() # 对角线图 第1个参数:2行 第2个参数:3列的网格 第3个参数:图形在网格的位置subplot(231)plot(x,y) # 垂直柱状图subplot(232)bar(x,y) # 水平柱状图subplot(233)barh(x,y) # 堆叠柱状图-颜色间隔su

python3绘图示例1(基于matplotlib)

#!/usr/bin/env python# -*- coding:utf-8 -*- import numpy as npimport matplotlib.pyplot as pltimport jsonfrom decimal import Decimal # 保留浮点类型jstring='{"name":"pro","price":12.05}'str=json.loads(jstring,parse_float=Decimal)prin

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

#!/usr/bin/env python# -*- coding:utf-8 -*- import os import numpy as npimport matplotlib as mpltfrom matplotlib import pyplot as pltfrom matplotlib.ticker import * # 整个图像为1个figure对象,figure对象包含多个Axes对象,每个Axes对象都拥有自己坐标轴的绘图区域# 调用figure时,则调用plot,然后plot调

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

#!/usr/bin/env python# -*- coding:utf-8 -*- import os import pylab as pyimport numpy as npfrom matplotlib import pyplot as pltimport matplotlib as mplt # matplotlib.get_config() 获取当前配置# 用户matplotlib配置文件路径path=mplt.get_configdir()print(path) # 当前matpl

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

#!/usr/bin/env python# -*- coding:utf-8 -*-from pylab import *from numpy import *import numpy # 数据点图-数据点平滑处理def moveing_average(ineterval,window_size): window=ones(int(window_size))/float(window_size) return convolve(ineterval,window,'same') t=linspa

基于matplotlib的数据可视化

matplotlib.pyplot(as mp or as plt)提供基于python语言的绘图函数 引用方式: import matplotlib.pyplot as mp / as plt 本章内容拟按官方手册(NumPy Reference, Release 1.14.5 )中的 plt 形式 像matlab一样,matplotlib.pyplot是一些命令样式函数. pyplot函数都可以创建图形.再图形中创建绘图区.再绘图区中画线.用标签装饰图形等操作. 在pyplot的函数调用中,

Matplotlib常用绘图示例入门

一.Matplotlib介绍 Matplotlib 是一个 Python 的 2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形.通过 Matplotlib,开发者可以仅需要几行代码,便可以生成绘图,直方图,功率谱,条形图,错误图,散点图等.Matplotlib使用NumPy进行数组运算,并调用一系列其他的Python库来实现硬件交互. 二.常用示例 环境:Jupyter(1.0.0) Ubuntu安装Jupyter Notebook 1.折线图 %matplotlib i

Python3绘图之Matplotlib(01)

1 First plots with Matplotlib 简单的绘图1 简单的绘图2 简单的绘图3 2 网格 = grid 3 设置坐标轴的取值范围 = axis xlim ylim 方法1:整体设置 [xmin, xmax, ymin, ymax]   ===>plt.axis([xmin, xmax, ymin, ymax]) 方法2:分别设置 plt.xlim([xmin, xmax]) plt.ylim([ymin, ymax]) 4 设置坐标含义标签 = label 5 设置图片的整

python matplotlib绘图大全(散点图、柱状图、饼图、极坐标图、热量图、三维图以及热图)

//2019.7.14晚matplotlib七种常见图像输出编程大全 七种图形汇总输出如下: import numpy as np #导入数据结构nmupy模块import matplotlib.pyplot as plt #导入matplotlib图像输出模块plt.rcParams["font.sans-serif"]=["SimHei"] #输出图像的标题可以为中文正常输出plt.rcParams["axes.unicode_minus"]