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()


  • 相关阅读:
    Linux工具[转]
    [C++]线程池 与 [Go] mapreduce
    快手面试代码题
    C++ note
    sudo与用户权限
    service 与 log日志
    tmux-cheatsheet
    [转]Linux下的常见信号总结
    记一个低级错误
    Github个人主页不显示提交记录的问题
  • 原文地址:https://www.cnblogs.com/NiceTime/p/10125218.html
Copyright © 2011-2022 走看看