2
votes

Here it appears that matplotlib's specgram returns 4 variables including the last which is a plot:

http://matplotlib.org/examples/pylab_examples/specgram_demo.html

But here it seems there is only 3 variables returned in the tuple:

https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/mlab.py#L478

Where is the missing code to generate the specgram plot? Perhaps I am just confused on the difference between pylab and matplotlib. Either way, I can't find the source.

1
and be warned, there is PR that does a bunch of work on this coming down the pipe. - tacaswell

1 Answers

5
votes

You're confusing the function that computes the data to be plotted with the function that plots the data.

mlab.specgram just computes the data, while the axes method specgram plots it.

Have a look at: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_axes.py#L5786

ipython is very useful for things like this. method_name? will display the relevant documentation and the location of the source file, while method_name?? will display the relevant code, as well.

Understanding where the source for a matplotlib function is can be a bit confusing. Basically, anything in matplotlib.pyplot is auto-generated. Essentially all of the plotting methods are actually methods of the Axes object.

Hopefully that gets you started. If no one else gives a better answer, I'll elaborate more in a bit, when I have more time.