0

The sample data is wav files from Kaggle: Emotional Speech database for classification problem

2018r...@mnit.ac.in's profile photo
2018r...@mnit.ac.in
unread,
12:00 AM (19 hours ago) 
to librosa

I am using the following code snippet, want to rcv the font size of the axes also the wav file length is 2 seconds long, but why is it plotting only for 1.5 seconds plz guide.

import matplotlib.pyplot as plt
import librosa
import librosa.display
import glob
    path=glob.glob('E:/Python_On_All_Dataset/Four emotion_for plot/*.wav') 
    
    fig, ax =  plt.subplots(nrows=7, ncols=3, sharex=True)
    plt.rcParams['font.size'] = '1'
    
    for i in range(7) :
       
        y, sr = librosa.load(path[i], sr=16000)
        librosa.display.waveplot(y, sr, ax=ax[i, 0])  # put wave in row i, column 0
      
        mfcc=librosa.feature.mfcc(y) 
        librosa.display.specshow(mfcc, x_axis='time', ax=ax[i, 1],cmap='viridis') # mfcc in row i, column 1
       
        S = librosa.feature.melspectrogram(y, sr)
        librosa.display.specshow(librosa.power_to_db(S), x_axis='time', y_axis='log', ax=ax[i, 2],cmap='viridis')  # spectrogram in row i, column 2

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • So the question is actually, how to adjust the x-tick labels, because all the data is plotted, it's just how the tick labels are auto formatted. – Trenton McKinney Aug 29 '21 at 19:18
  • You can set the xlim for each axes: `ax[i, 0].set_xlim(0, 4)` – Trenton McKinney Aug 29 '21 at 19:21
  • modified the line as `librosa.display.waveplot(y, sr, ax[i, 0].set_xlim(0, 2))` but its giving error as `'<=' not supported between instances of 'tuple' and 'int'` – KRISHNA CHAUHAN Aug 29 '21 at 19:41
  • don't set it inside waveplot. It should be on the next line, one for each column of the row. – Trenton McKinney Aug 29 '21 at 19:42
  • Thank you sir it's working Though probably I need to raise another question for the next query here, the mfcc and melspec are not plotted for a complete 2 sec but black, as you see in my question figure plot 4. why is it so. BTW how to accept this as an answer? – KRISHNA CHAUHAN Aug 29 '21 at 19:49
  • Setting the xlim is already an answer, I would close the question as a duplicate. As for figure 4, that file is shorter so there is no more data. – Trenton McKinney Aug 29 '21 at 19:51
  • 1
    Does this answer your question? [Python, Matplotlib, subplot: How to set the axis range?](https://stackoverflow.com/questions/2849286/python-matplotlib-subplot-how-to-set-the-axis-range) – Trenton McKinney Aug 29 '21 at 20:16
  • Sorry for the late update sir, I have changed the waveform length accordingly as `ax[i, 0].set_xlim(0, 1.7)` – KRISHNA CHAUHAN Aug 31 '21 at 07:18
  • Can some one tell me how to close this discussion – KRISHNA CHAUHAN Aug 31 '21 at 07:19

0 Answers0