1

I used the specgram to plot the spectrogram of my signal. However, the Y axis display the frequency in Hz. So I want to know how I can scale it down by a factor of 1000 so instead of 6000 it becomes 6, and I can put the label as kHz instead of Hz. Thanks

I also have a problem with the subplot that the label on the right overlap with the left subplot when the image window zoom to a smaller size. Any idea how to avoid that?

enter image description here

self.trjFig = plt.figure()
self.trjFigCanvas = FigureCanvas(self.trjFig)
self.trjFigAx = self.trjFig.add_subplot(121)
self.trjFigAx.set_xlim([-0.5, 0.5])
self.trjFigAx.set_ylim([-0.5, 0.5])
self.trjFigAx.set_title('Trajectory')
self.trjFigAx.plot(self.data[:, 0], self.data[:, 1], ".")

self.specFigAx = self.trjFig.add_subplot(122)
self.specFigAx.set_title('Spectrogram')
self.specFigAx.set_ylabel("Frequency (Hz)")
self.specFigAx.set_xlabel("Time (s)")
self.trjFigToolbar = NavigationToolbar(self.trjFigCanvas,self)
self.specFigAx.specgram(self.velSound, NFFT = 1024, Fs = FS, noverlap = 900, cmap= plt.cm.gist_heat)
self.trjFigCanvas.draw()
J_yang
  • 2,672
  • 8
  • 32
  • 61
  • Showing some sample code where we can try out might get you quicker answers ... – tfv Sep 13 '16 at 15:27
  • Hi tfv, ousted added – J_yang Sep 13 '16 at 15:30
  • Check [this](http://stackoverflow.com/questions/12608788/changing-the-tick-frequency-on-x-or-y-axis-in-matplotlib) – Repiklis Sep 13 '16 at 15:35
  • Hi Repiklis, However the problem is that yticks will need me to replace the list of y with a new range. The problem is that I plot it with specgram. How can I get the list of y value? – J_yang Sep 13 '16 at 15:50
  • You can use `self.trjFigAx.get_yticks()` to get these and replace. – Ed Smith Sep 14 '16 at 08:02
  • Hi Ed Smith, I put self.specFigAx.set_yticks(np.arange(0 , max(self.specFigAx.get_yticks()/1000), 1)) but as a result it only draw 7 ticks from 0~6 out of the maximum range 6000. So on the graph was just a tiny bit that get drawn rather than scaling it down. Any suggestion – J_yang Sep 14 '16 at 08:43

0 Answers0