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=linspace(-4,4,100)y=sign(t)+randn(len(t))*0.1plot(t,y,‘k.‘)

y_av=moveing_average(y,10)plot(t,y_av,‘r‘)

xlabel(‘time‘)ylabel(‘value‘)grid(True)show()

# 图2-一个为曲线图 一个为折线图windows=[‘flat‘,‘hanning‘,‘hamming‘,‘bartlett‘,‘blackman‘]

def smooth(x,window_len=11,window=‘hanning‘):    if x.ndim!=1:        print(‘ere‘)

if x.size<window_len:        print(‘ee2‘)

if window_len<3:        return x

if not window  in windows:        print(‘4‘)

s=numpy.r_[x[window_len-1:0:-1],x,x[-1:-window_len:-1]]

if window==‘flat‘:        w=numpy.ones(window_len,‘d‘)    else:        w=eval(‘numpy.‘+window+‘(window_len)‘)        y=numpy.convolve(w/w.sum(),s,mode=‘valid‘)    return y

t=linspace(-4,4,100)x=sign(t)xn=x+randn(len(t))*0.1

y=smooth(x)

ws=31subplot(211)plot(ones(ws))

for w in windows[1:]:    eval(‘plot(‘+w+‘(ws))‘)    axis([0,30,0,1.1])    legend(windows)    title(‘smoothing‘)

subplot(212)plot(x)plot(xn)for w in windows[1:]:    plot(smooth(xn,10,w))I=[‘original ‘,‘noise‘]I.extend(windows)legend(I)

title(‘signal‘)show()

原文地址:https://www.cnblogs.com/NiceTime/p/10125218.html

时间: 2024-08-25 18:26:19

python3绘图示例3(基于matplotlib:折线图等)的相关文章

python matplotlib 折线图的制作

python  matplotlib和random 折线图的制作 1.库的导入 import matplotlib.pyplot as plt # 导入模块 import random 2.创建画布并设置中文 # 1)创建画布(容器层) plt.figure("北京上海温度", figsize=(10, 5)) # 10为绘图对象长度,5为宽度 plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 plt.rcParams[

matplotlib折线图

绘制折线图:参考https://baijiahao.baidu.com/s?id=1608586625622704613           (3)近10年GDP变化的曲线图,及三次产业GDP变化的曲线图.数据: [['指标', '2017年', '2016年', '2015年', '2014年', '2013年', '2012年', '2011年', '2010年', '2009年', '2008年'], ['国民总收入(亿元)', 824828.4, 740598.7, 686449.6,

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绘图示例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绘图示例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

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

折线图-----插件

(function( w ) { /* * constructor { LineChart } 折线图构造函数 * param { ctx: Context } 绘图上下文 * param { paddingArr: Array } 折线图到画布四边的距离,存储顺序为上右下左 * param { arrowArr: Array } 折线图中箭头的宽和高 * param { data: Array } 存储了折线图中所需的数据 * */ function LineChart( ctx, data,

python中matplotlib绘图封装类之折线图、条状图、圆饼图

DrawHelper.py封装类源码: 1 import matplotlib 2 import matplotlib.pyplot as plt 3 import numpy as np 4 5 class DrawHelper: 6 def __init__(self): 7 # 指定默认字体 下面三条代码用来解决绘图中出现的乱码 8 matplotlib.rcParams['font.sans-serif'] = ['SimHei'] 9 matplotlib.rcParams['font