# Extract the matrix (numpy array) with which the spectrogram is generated

**URL:** <https://discourse.obspy.org/t/extract-the-matrix-numpy-array-with-which-the-spectrogram-is-generated/1613>\
**Category:** Usage Questions\
**Created:** [January 12, 2023, 9:19am UTC](https://discourse.obspy.org/t/extract-the-matrix-numpy-array-with-which-the-spectrogram-is-generated/1613 "2023-01-12T09:19:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hisv95](https://discourse.obspy.org/user_avatar/discourse.obspy.org/hisv95/32/643_2.png) [@hisv95](https://discourse.obspy.org/u/hisv95)\
**Post date:** [January 12, 2023, 9:19am UTC](https://discourse.obspy.org/t/extract-the-matrix-numpy-array-with-which-the-spectrogram-is-generated/1613/1 "2023-01-12T09:19:39Z")

</div>

Hello,

I would like to ask if there is a way to obtain, from a spectrogram, the data matrix that generates it.  
Reviewing the source code of the spectrogram (Obspy), the numpy array (matrix) that generates the image is called “ **specgram** ”.  
Next, I put an example (which comes within the source code of the spectrogram) where it generates the graph from this variable. ax.imshow( **specgram** ,interpolation=“nearest”, extent=extent, \*\*kwargs).

---

<div class="post-metadata">

**Author:** ![trichter](https://discourse.obspy.org/user_avatar/discourse.obspy.org/trichter/32/226_2.png) [@trichter](https://discourse.obspy.org/u/trichter)\
**Post date:** [January 13, 2023, 5:50pm UTC](https://discourse.obspy.org/t/extract-the-matrix-numpy-array-with-which-the-spectrogram-is-generated/1613/2 "2023-01-13T17:50:28Z")

</div>

Hi,

please have alook at this thread:

> [@obspy.imaging.spectrogram - output data](https://discourse.obspy.org/t/obspy-imaging-spectrogram-output-data/903):
>
> Hi there, Does anybody know how to output the data from the obspy function spectrogram (not only as an image file)? Description of work flow: 1.read in one seismic trace (SEGY format) - OK calculate and plot the spectrogram using obspy.imaging.spectrogram - OK output the image of the spectrogram as a PNG file - OK output the data points, as floating numbers - NOT POSSIBLE ?? My code is the following: st=obspy.read(\seismic\trace.segy) st\_spec=st.spectrogram(log=True, wlen=0.02, …
