0

I'm trying to plot a colour map and I need to use mlab.specgram() to perform a cross-correlation of two functions in the frequency domain, so I can't use pyplot.specgram(). I used pyplot.imshow in order to plot a colour map of the cross-correlation, but as a result the axes are just index numbers rather than the actual time values corresponding to the power shown in the colour map.

I've tried to change the labels using xticks()/yticks() and the extent argument, but all it does is show me a small portion of my colour map instead of changing the labels.

Is there a way for me the change the scale of my axes to match the actual frequency and time?

For reference:

# My spectrograms:
spec_H1, freqs, t = mlab.specgram(H_filt, NFFT=NFFT, Fs=fs, noverlap=NOVL, mode=mode) 
spec_L1, freqs, t = mlab.specgram(L_filt, NFFT=NFFT, Fs=fs, noverlap=NOVL, mode=mode)

# The cross-correlation:
X = np.real(spec_H1 * np.conj(spec_L1))

# The figure:
plt.figure(figsize=(10,10))
plt.imshow(abs(X), cmap = 'jet')
plt.colorbar() 
plt.ylim(0,200)
plt.xlim(0,500)

The figure

As you can see, for example, the time axis (x) should run from 0 to 4 seconds, but it's sampled such that it runs from 0 to 500. How do I change this?

JohanC
  • 71,591
  • 8
  • 33
  • 66
Petra
  • 195
  • 1
  • 1
  • 10
  • `imshow` accepts a parameter [`extent=...`](https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.imshow.html) which probably helps. – JohanC Jan 23 '20 at 20:11
  • Like I mentioned in the question, I tried extent but it seems to only take a slice of the graph, rather than actually changing the scale. Am I applying it wrong? (Thanks for editing the question, by the way. I'm new to this!) – Petra Jan 23 '20 at 20:27
  • Extent doesn't change the image, only what's shown on the axes. You should first try with removing `plt.xlim(0,500)` and adding `extent=[0,4,0,200]` to `imshow` – JohanC Jan 23 '20 at 20:33
  • Ahhh, okay I see; the data was small and looked like it had zeroed out. Thank you so much! – Petra Jan 23 '20 at 20:47

0 Answers0