Skip to content

Question: is it possible to draw 'boxes' IN the spectrogram (using the x and y axis values) #634

Answered by sammlapp
rduivenvoorde asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, we don't have any currently implemented features for drawing boxes on a spectrogram. However, it's pretty easy to draw boxes on a pyplot figure (over top of a spectrogram) using the frequency and time limits. Here's an example:

import matplotlib.patches as patches
import matplotlib.pyplot as plt
from opensoundscape.audio import Audio
from opensoundscape.spectrogram import Spectrogram

f = './audio.wav' #path to audio file

# create Spectrogram object
spec = Spectrogram.from_audio(Audio.from_file(f).trim(1,6)).bandpass(0,10000)

# Create figure and axes
fig, ax = plt.subplots()

# Display the spectrogram
mesh = ax.pcolormesh(spec.times, spec.frequencies, spec.spectrogram,shading="auto"…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by sammlapp
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #376 on January 08, 2023 03:57.