Colorbar not working with specgram

Hello everybody,
this is my first post in this list.

I'm plotting a spectrogram with

Pxx, freqs, bins, im = specgram(y, nfft=256, f_sampling=12000)

and i want to add a colorbar with

colorbar()

The problem is that the color scale seems to be wrong with respect to
the data in Pxx, i.e. Pxx is of the order of 1e-2 while in the colorbar
i have tick values spanning from -20 to -180. What is the problem??

Thanks in advance!

Davide

davide lasagna wrote:

Hello everybody,
this is my first post in this list.

I'm plotting a spectrogram with

Pxx, freqs, bins, im = specgram(y, nfft=256, f_sampling=12000)

and i want to add a colorbar with

colorbar()

The problem is that the color scale seems to be wrong with respect to
the data in Pxx, i.e. Pxx is of the order of 1e-2 while in the colorbar
i have tick values spanning from -20 to -180. What is the problem??

specgram and psd plot power in decibels: 10*log10(Pxx).

Because they involve heavy computation and application-specific choices, like the decibel scale, they really should not be axes methods.

You can make a function plot the spectrogram however you like by looking at the source code in the Axes.specgram method (the pyplot specgram function is just a thin wrapper for this method), which is using mlab.specgram to do the calculation and is then just scaling and plotting.

Eric

···

Thanks in advance!

Davide

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Thanks Eric for pointing out this. However i've found that psd and
specgram plot 10*log10*(Pxx/max(Pxx)), so i'll have a range from 0 db
down.
Anyway, what do you mean by "should not be axes method"?
Do you mean using the array output of specgram and psd and plotting that
result by myself?

Cheers

Davide

···

On Tue, 2009-07-21 at 09:12 -1000, Eric Firing wrote:

davide lasagna wrote:
> Hello everybody,
> this is my first post in this list.
>
> I'm plotting a spectrogram with
>
> Pxx, freqs, bins, im = specgram(y, nfft=256, f_sampling=12000)
>
> and i want to add a colorbar with
>
> colorbar()
>
>
> The problem is that the color scale seems to be wrong with respect to
> the data in Pxx, i.e. Pxx is of the order of 1e-2 while in the colorbar
> i have tick values spanning from -20 to -180. What is the problem??

specgram and psd plot power in decibels: 10*log10(Pxx).

Because they involve heavy computation and application-specific choices,
like the decibel scale, they really should not be axes methods.

You can make a function plot the spectrogram however you like by looking
at the source code in the Axes.specgram method (the pyplot specgram
function is just a thin wrapper for this method), which is using
mlab.specgram to do the calculation and is then just scaling and plotting.

Eric

>
> Thanks in advance!
>
>
> Davide
>
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> matplotlib-users List Signup and Options

davide lasagna wrote:

Thanks Eric for pointing out this. However i've found that psd and
specgram plot 10*log10*(Pxx/max(Pxx)), so i'll have a range from 0 db
down.

Aha, I wasn't looking closely enough!

Anyway, what do you mean by "should not be axes method"?

That was a side remark about what the Axes class should do or not do. I would prefer that it stick to plotting. For example, at present it does not have a method for empirical orthogonal functions, or for wavelets--and that's good, it shouldn't. Numerical code (usually in numpy or scipy) should do the calculations, and then the result should be plotted using Axes methods or pyplot functions for line plotting, contouring, making images, etc. So getting back to the specgram, I would prefer that it be given as an example--a script combining the calculation with the plotting--rather than having calculation and plotting done in an Axes method.

Do you mean using the array output of specgram and psd and plotting that
result by myself?

The calculations are being done by functions in the matplotlib.mlab module, so yes, I suggest using those functions directly (not the pyplot functions that wrap the Axes methods that call the mlab functions and then plot the result) and then doing your own scaling and plotting. The Axes specgram method might guide you in the latter (giving an example of how to use imshow, for example), but if you write your own function you can make it do exactly what you want instead of accepting the scaling choice imposed by the Axes method.

Eric

···

Cheers

Davide
On Tue, 2009-07-21 at 09:12 -1000, Eric Firing wrote:

davide lasagna wrote:

Hello everybody,
this is my first post in this list.

I'm plotting a spectrogram with

Pxx, freqs, bins, im = specgram(y, nfft=256, f_sampling=12000)

and i want to add a colorbar with

colorbar()

The problem is that the color scale seems to be wrong with respect to
the data in Pxx, i.e. Pxx is of the order of 1e-2 while in the colorbar
i have tick values spanning from -20 to -180. What is the problem??

specgram and psd plot power in decibels: 10*log10(Pxx).

Because they involve heavy computation and application-specific choices, like the decibel scale, they really should not be axes methods.

You can make a function plot the spectrogram however you like by looking at the source code in the Axes.specgram method (the pyplot specgram function is just a thin wrapper for this method), which is using mlab.specgram to do the calculation and is then just scaling and plotting.

Eric

Thanks in advance!

Davide

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options