Python,Matplotlib,子图:如何设置轴范围? [英] Python, Matplotlib, subplot: How to set the axis range?

查看:1504
本文介绍了Python,Matplotlib,子图:如何设置轴范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将第二个子图的y轴范围设置为[0,1000]? 我的数据(文本文件中的一列)的FFT图导致一个(inf.?)尖峰,因此实际数据不可见.

How can I set the y axis range of the second subplot to e.g. [0,1000] ? The FFT plot of my data (a column in a text file) results in a (inf.?) spike so that the actual data is not visible.

pylab.ylim([0,1000])

不幸的是,

没有任何作用.这是整个脚本:

has no effect, unfortunately. This is the whole script:

# based on http://www.swharden.com/blog/2009-01-21-signal-filtering-with-python/
import numpy, scipy, pylab, random

xs = []
rawsignal = []
with open("test.dat", 'r') as f:
      for line in f:
            if line[0] != '#' and len(line) > 0:
                xs.append( int( line.split()[0] ) )
                rawsignal.append( int( line.split()[1] ) )

h, w = 3, 1
pylab.figure(figsize=(12,9))
pylab.subplots_adjust(hspace=.7)

pylab.subplot(h,w,1)
pylab.title("Signal")
pylab.plot(xs,rawsignal)

pylab.subplot(h,w,2)
pylab.title("FFT")
fft = scipy.fft(rawsignal)
#~ pylab.axis([None,None,0,1000])
pylab.ylim([0,1000])
pylab.plot(abs(fft))

pylab.savefig("SIG.png",dpi=200)
pylab.show()

其他改进也受到赞赏!

推荐答案

http://www.mofeel.net/582-comp-soft-sys-matlab/54166.aspx

 pylab.ylim([0,1000])

注意:该命令必须在绘图后执行!

Note: The command has to be executed after the plot!

这篇关于Python,Matplotlib,子图:如何设置轴范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆