# Showing specific values in an STFT plot

I have a short term fourier transform plot that I plot using matplotlib's pcolormesh() function:

If I zoom in the plot, I see this:

Now, I want the plot to just show the zoomed-in range on the y-axis - till 4 or 3 kHz. Is there any way to do this without having to manually zoom in? I want to do a comparison for multiple waveforms in the frequency range as this is my passband in the passband filter I apply on the data.

Here is the code I use to compute and plot the stft:

sampleFreq, segmentTimes, stftX = sp.stft(filteredY, fs)
segmentTimes += (1.5 / 1000)
plt.ylabel("Frequency (Hz)")
plt.xlabel("Time (s)")
plt.title("Sort Term FFT")
plt.show()


I add 1.5 to the segmentTimes because I trim my original data from 1.5 to 2.5 ms, and for some reason, if I don't add 1.5 here, the stft starts from 0.0 s. And the division by 1000 is for conversion to seconds from milliseconds.

Also, sampleFreq and segmentTimes are simple lists but stftX is a list of lists.

Use matplotlib.pyplot's axis() function as follows:

# show section based on bandpass filter cut-off frequencies
plt.title("Zoomed Short Term Fourier Transform")
plt.xlabel("Time (s)")
plt.ylabel("Frequency Magnitude")

where high_pass and low_pass are the frequency cut-offs within which you want to display the y-axis data.