python3绘图示例3(基于matplotlib:折线图等)
Posted 新美好时代
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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()
以上是关于python3绘图示例3(基于matplotlib:折线图等)的主要内容,如果未能解决你的问题,请参考以下文章
python3绘图示例6-1(基于matplotlib,绘图流程介绍及设置等)
python3绘图示例6-2(基于matplotlib,绘图流程介绍及设置等)