add a marker to librosa waveplot python

The Libra.display.waveplot() does not, as far as I can tell, have the ability to set markers. I have no knowledge of sound waveforms. I don’t know what output I want, but matplotlib seems to be able to handle it.

import librosa.display
import matplotlib.pyplot as plt
import numpy as np

filename = '/content/test_music.mp3'

def main():
    # Load the mp3 file and define variables
    y, sr = librosa.load(filename, duration=10)
    fig, ax = plt.subplots(nrows=1, sharex=True, sharey=True, figsize=(16,9))

    y_harm, y_perc = librosa.effects.hpss(y)
    librosa.display.waveplot(y_harm, sr=sr, alpha=0.25, ax=ax)
    librosa.display.waveplot(y_perc, sr=sr, color='r', alpha=0.5, ax=ax)
    ax.set(title='Harmonic + Percussive')
    ax.plot(np.arange(1,220501), y_harm, marker='o', markersize=10)
    plt.show()


if __name__ == '__main__':
    main()

enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top