Just as a general comment - perhaps not useful in your case - we have the 
same sort of requirement and find the periodogram facility (specgram) in 
pylab very useful for showing the change in PSD over time - highlighting 
resonances and how they vary in proportion to other functions of time 
(plotted on sub-graphs).





Stephen George <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED]
14/06/2007 03:52 PM

To
matplotlib <Matplotlib-users@lists.sourceforge.net>
cc

Subject
[Matplotlib-users] get_xlim() - where am I going wrong







Hi,

I have 2 graphs on one figure.
Graph one - subplot(2,1,1)    velocities vs  ( Time or SampleIndex) 
depending in input args
Graph two - subplot(2,1,2)   psd() - power spectrum to help us find the 
resonances in velocities

As system goes through a number of different states, the resonances 
change during the cycle, so I need to zoomIn GraphOne to an area of 
interest, then re-calc the power spectrum on that portion of data only.

I have something that works in the xaxis=SampleIndex scenario, but fails 
in the xaxis=Time scenario, I am wondering if I am going about it the 
right way.

The following page has 4 graphs that show what I have working now (2 
graphs of velocity vs SampleNo), and the failing case (2 graphs of 
Velocity Vs Time)
*http://tinyurl.com/2xpyly
*
I'll describe what I got.

I connected my function RecalcPowerSpectrum  to ReleaseButton event
            pylab.connect( 'button_release_event', RecalcPowerSpectrum)


It's ugly and crude, but if GraphOne is a velocity vs sampleIndex, the 
following works.
My issues start when you look at how I am slicing (if thats the right 
word) the array I pass into psd() and where those values come from.

def RecalcPowerSpectrum( event ): 
    global myAxis
    global lastXstart
    global lastXend

    xlim = myAxis.get_xlim()

    xstart = int(xlim[0])
    xend = int(xlim[1])
 
    if xstart != lastXstart or xend != lastXend:
        print '%s event detected, re-calc power spectrum' % event.name
        lastXstart, lastXend = xstart, xend
        lastXlimits = xlim
        print 'xlim1 =', xstart
        print 'xlim2 =', xend 
        pylab.cla()
        if secondGraph == 'fft':# (plot UDR1 points)
            Fs = 2 * targetvel
            fftdata = pylab.psd(vel[2*xstart:2*xend], NFFT=winsize, 
Fs=Fs, detrend=pylab.mlab.detrend_linear, 
window=pylab.mlab.window_hanning, noverlap=overlap)
        else: #must be a fft2 (plot UDR2 points)
            Fs = targetvel
            fftdata = pylab.psd(combined[xstart:xend], NFFT=winsize, 
Fs=Fs, detrend=pylab.mlab.detrend_linear, 
window=pylab.mlab.window_hanning, noverlap=overlap)


This fails when I run my program to plot with xaxis in time as the 
values returned by get_xlim() are small (0.46408074411240841, 
0.53334652681575301), once I int() these values they are both 0

Clearly I am trying to work with the wrong values. I actually want to 
get the indexes of these values. So I can pass the proper slice of the 
original array into the psd function.


So my questions.
1) Is there a way to get the indexes (not the values) of the portion of 
the line actually showing on screen
2) Is there a way to get a copy of the portion of the data displayed on 
screen (in a new array) ?
3) Is there a better way of linking psd so it performs the spectrum 
analysis only on the portion of data on screen?

*
*Thanks for your help
Steve

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________



UNITED GROUP
This email message is the property of United Group. The information in this 
email is confidential and may be legally privileged. It is intended solely for 
the addressee. Access to this email by anyone else is unauthorised. If you are 
not the intended recipient, you may not disclose, copy or distribute this 
email, nor take or omit to take any action in reliance on it. United Group 
accepts no liability for any damage caused by this email or any attachments due 
to viruses, interference, interception, corruption or unauthorised access.
If you have received this email in error, please notify United Group 
immediately by email to the sender's email address and delete this document.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to