From 6a19dbed202ec26eb2fd151b7c11d9c49613ee19 Mon Sep 17 00:00:00 2001 From: Joel Mathew Thomas <90510078+joelmathewthomas@users.noreply.github.com> Date: Mon, 6 Jan 2025 22:28:08 +0530 Subject: [PATCH] add code to display spectogram --- requirements.txt | 4 ++++ src/spectogram/display.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/spectogram/display.py diff --git a/requirements.txt b/requirements.txt index 27debed..470e19c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -38,6 +38,7 @@ llvmlite==0.43.0 Markdown==3.7 markdown-it-py==3.0.0 MarkupSafe==3.0.2 +matplotlib==3.10.0 matplotlib-inline==0.1.7 mdurl==0.1.2 ml-dtypes==0.4.1 @@ -77,6 +78,9 @@ pure_eval==0.2.3 pycparser==2.22 Pygments==2.18.0 pyparsing==3.2.0 +PyQt6==6.8.0 +PyQt6-Qt6==6.8.1 +PyQt6_sip==13.9.1 pytest==8.3.4 python-dateutil==2.9.0.post0 PyYAML==6.0.2 diff --git a/src/spectogram/display.py b/src/spectogram/display.py new file mode 100644 index 0000000..a41b2c0 --- /dev/null +++ b/src/spectogram/display.py @@ -0,0 +1,18 @@ +import matplotlib.pyplot as plt +import librosa.display +import numpy as np + +def display_spectrogram(spec_array: np.ndarray, plot_data: dict): + """ + Displays a spectrogram array using Matplotlib. + + Args: + spec_array (np.ndarray): Spectrogram array (in decibels). + plot_data (dict): Metadata for plotting (e.g., sr, x_axis, y_axis). + """ + plt.figure(figsize=(10, 4)) + librosa.display.specshow(spec_array, sr=plot_data['sr'], x_axis=plot_data['x_axis'], y_axis=plot_data['y_axis']) + plt.colorbar(format='%+2.0f dB') + plt.title(f"Spectrogram ({plot_data['y_axis'].upper()} axis)") + plt.tight_layout() + plt.show()