zoukankan      html  css  js  c++  java
  • 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.1
    plot(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=31
    subplot(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()


  • 相关阅读:
    nginx编译安装
    使用scp命令,不同服务器之间拷备文件
    cpu负载过高排查与解决
    Docker安装
    sftp安装
    nginx登陆验证 [done]
    git常用命令
    python常见问题记录
    升级openssl
    rsync使用
  • 原文地址:https://www.cnblogs.com/NiceTime/p/10125218.html
Copyright © 2011-2022 走看看