You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parameter Fs initialization missing in Axes.specgram() #9100
the docstring of parameter Fs of matplotlib.pyplot.specgram() says that the default value is 2 but the default value in the function signature is None.
specgram(x, NFFT=None, Fs=None, Fc=None, ...
...
Fs : scalar
The sampling frequency (samples per time unit). It is used
to calculate the Fourier frequencies, freqs, in cycles per time
unit. The default value is 2.
Expected outcome
Either write None in the docstring or make change the default value of Fs to 2.
Matplotlib version
Operating System: OSX 10.11.6
Matplotlib Version: 2.0.2
Python Version: 3.5.4
Jupyter Version (if applicable): notebook server 5.0.0, IPython 6.1.0
I do not think this is a problem, the default value used is2.
specgram just passes Fs down into a helper function (which is where the 2 is finally hard-coded). I do not think we do want put the default value into every signature of that calls the helper (as we would then have the default value encoded a bunch of places instead of just one).
I am against changing the docstring to say it defaults to None as the value needs to be an integer at some point to turn the crank on the math and we use the value 2.
ifNFFTisNone:
NFFT=256# same default as in mlab.specgram()ifFcisNone:
Fc=0# same default as in mlab._spectral_helper()ifnoverlapisNone:
noverlap=128# same default as in mlab.specgram()
which misses out setting Fs = 2. (Also this means that the defaults are hardcoded anyway, so having default kwargs instead of all these if statements seems more sensible to me)
Reacted by andreh7, maddysj4, Tim Hoffmann and Nevena
sorry for the late reply, I'm looking into this now. What about the vmin and vmax parameters in the signature you proposed for axes/_axes:Axes.specgram in #9100 (comment) ? These parameters appear in the code (currently they default to None).
I also see that (at least in the current head d02024e), mlab.specgram() would then have different default values than the ones proposed in the above comment. Should these be changed as well ?
I'd suggest that ax.specgram() should be changed to:
pad_xextent= (NFFT-noverlap) /freq[-1] /2
...that way you aren't updating defaults in two places.
I find this call strange anyway. I'd have thought: xmin = t[0]-(t[1]-t[0])/2. and xmax = t[-1]+(t[-2]-t[-1])/2. would be more straightforward. But I haven't tested.
changed the title [-]docstring of parameter Fs of matplotlib.pyplot.specgram() inconsistent with default value[/-][+]Parameter Fs initialization missing in matplotlib.pyplot.specgram()[/+]on Mar 31, 2020
changed the title [-]Parameter Fs initialization missing in matplotlib.pyplot.specgram()[/-][+]Parameter Fs initialization missing in Axes.specgram()[/+]on Mar 31, 2020
Activity
tacaswell commentedon Aug 26, 2017
I do not think this is a problem, the default value used is
2.specgramjust passesFsdown into a helper function (which is where the 2 is finally hard-coded). I do not think we do want put the default value into every signature of that calls the helper (as we would then have the default value encoded a bunch of places instead of just one).I am against changing the docstring to say it defaults to
Noneas the value needs to be an integer at some point to turn the crank on the math and we use the value2.andreh7 commentedon Aug 26, 2017
When I do:
I get an exception:
while when I do:
I get a spectrogram graph.
So the effective default value is not 2.
dstansby commentedon Aug 26, 2017
Very early on in the specgram code is:
which misses out setting
Fs = 2. (Also this means that the defaults are hardcoded anyway, so having default kwargs instead of all these if statements seems more sensible to me)tacaswell commentedon Aug 27, 2017
Ah, sorry I was looking at
mlab.specgramnotAxes.specgram🐑 .👍 to moving the default values up into the signature of
Axes.specgram(and regenerating pyplot) for as many of the kwargs as make sense.tacaswell commentedon Aug 27, 2017
@andreh7 Want to take a shot at this?
tacaswell commentedon Aug 27, 2017
I would go with everything listed in
Exact work:
axes/_axes:Axes.specgrammethod signature to match the aboveNonehandling (to not break people who are explicitly passing inNoneto mean 'do the default thing'Fs=Noneto default to 2 to fix the bugFs=Noneto the test suite (does not need to be an image test)andreh7 commentedon Sep 3, 2017
sorry for the late reply, I'm looking into this now. What about the
vminandvmaxparameters in the signature you proposed foraxes/_axes:Axes.specgramin #9100 (comment) ? These parameters appear in the code (currently they default toNone).I also see that (at least in the current head d02024e),
mlab.specgram()would then have different default values than the ones proposed in the above comment. Should these be changed as well ?changed default values of Axes.specgram() as proposed in matplotlib#9…
tacaswell commentedon Sep 24, 2017
@andreh7 Can you open a PR with that commit?
jklymak commentedon Sep 24, 2017
I'd suggest that
ax.specgram()should be changed to:...that way you aren't updating defaults in two places.
I find this call strange anyway. I'd have thought:
xmin = t[0]-(t[1]-t[0])/2.andxmax = t[-1]+(t[-2]-t[-1])/2.would be more straightforward. But I haven't tested.andreh7 commentedon Sep 25, 2017
@tacaswell I created pr #9221
What about the default values in
mlab.specgram()(see my question in #9100 (comment) ) ?[-]docstring of parameter Fs of matplotlib.pyplot.specgram() inconsistent with default value[/-][+]Parameter Fs initialization missing in matplotlib.pyplot.specgram()[/+][-]Parameter Fs initialization missing in matplotlib.pyplot.specgram()[/-][+]Parameter Fs initialization missing in Axes.specgram()[/+]