About how to specify the x-axis y-axis range in matplolib

Asked 2 years ago, Updated 2 years ago, 57 views

In the code below, you want to limit the y-axis from 0 to 1000 for the second plot.

FFT has an infinite number, so I'm just going to cut it to the top 1000.

import scipy
from matplotlib import pylab

xs = []
rawsignal = []
with open("myfile.txt", '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)
Plot pylab. ((fft abs)) # limited scope of the y-axis here.

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

matplotlib python

2022-09-21 21:34

1 Answers

pylab.plot(abs(fft)) after

pylab.ylim([0,1000])

Please add.


2022-09-21 21:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.