Commits

clee  committed a4b1627

rename plot->plots, working plotspec

  • Participants
  • Parent commits a51bf2f

Comments (0)

Files changed (4)

File examples/synthetic2.py

 twopi = 2*3.1415
 
 # create a list of different sin waves at different frequencies
-ss = [np.sin(twopi*f*t) for f in [5,10,20,30,40,50,100,200,400]]
+ss = [np.sin(twopi*f*t) for f in [5,10,20,30,50]]
 y = np.zeros(L,dtype='float64')
 
 for s in ss:  y+= s
 from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, \
      AnnotationBbox
 from matplotlib.cbook import get_sample_data
+from mpl_toolkits.axes_grid1 import make_axes_locatable
+from mpl_toolkits.axes_grid1 import host_subplot
 
 f = plt.figure()
-fa = plt.subplot(211)
-plt.plot(y)
-ax=plt.subplot(212)
-# plt.setp(ax, yticks=[10,25,50])
-plt.imshow(rsy,aspect='auto')
-plt.ylabel('frequency(Hz)')
-yloc,ylab=plt.yticks()
-plt.title('Stockwell transform spectrogram')
+# extent = 0, T, 0, Fs/2.0
+# plt.imshow(rsy,extent=extent,aspect='auto', origin='lower')
 
-f2 = plt.figure()
-fa2 = plt.subplot(211)
-plt.plot(y)
-ax2_212=plt.subplot(212)
-# plt.setp(ax, yticks=[10,25,50])
-plt.imshow(mty,aspect='auto')
-plt.ylabel('frequency(Hz)')
-yloc2,ylab2=plt.yticks()
-plt.title("multi-taper stockwell transform spectrogram")
+def plotspec(psx, fs, lofreq=None, hifreq=None, t1=None, t2=None):
+    extent = [0,psx.shape[1], 0.0, fs/2.0]
+    if t1 != None and t2 != None:
+        extent[0] = t1
+        extent[1] = t2
+    if lofreq != None:
+        extent[2] = lofreq
+    if hifreq != None:
+        extent[3] = hifreq
+    
+    return plt.imshow(psx, extent=extent, aspect='auto', origin='lower')
 
-from mpl_toolkits.axes_grid1 import make_axes_locatable
+plotspec(rsy, fs=Fs, t1=0, t2=T)
+
+if 0:
+    f = plt.figure()
+    fa = plt.subplot(311)
+    plt.plot(y)
+    ax=plt.subplot(312)
+    # plt.setp(ax, yticks=[10,25,50])
+    plt.imshow(rsy,aspect='auto')
+    plt.ylabel('frequency(Hz)')
+    yloc,ylab=plt.yticks()
+    plt.title('Stockwell transform spectrogram')
+    phase1 = plt.subplot(313)
+
+if 0:
+    f2 = plt.figure()
+    fa2 = plt.subplot(211)
+    plt.plot(y)
+    ax2_212=plt.subplot(212)
+    # plt.setp(ax, yticks=[10,25,50])
+    plt.imshow(mty,aspect='auto')
+    plt.ylabel('frequency(Hz)')
+    yloc2,ylab2=plt.yticks()
+    plt.title("multi-taper stockwell transform spectrogram")
+
+
 # divider = make_axes_locatable(ax)
 #cax = divider.append_axes("right", size="5%", pad=0.05)
 
 
-from mpl_toolkits.axes_grid1 import host_subplot
+

File stockwell/__init__.py

 """
 from __future__ import division
 
+from st import *
+
 def stfreq(f,length, srate):
 	"""
         [int] = stfreq(f,length, srate)

File stockwell/plot.py

-import matplotlib.pyplot as plt
-
-from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, \
-     AnnotationBbox
-
-from mpl_toolkits.axes_grid1 import host_subplot
-
-
-def stpowerstack(x,stx):
-    """
-    need to add row labels
-    """
-    ax1=host_subplot(211)
-    plt.plot(x)
-    ax2 = host_subplot(212)
-    #pax2 = ax2.twinx()
-    #pax2.set_ylabel('frequency(Hz)')
-    plt.imshow(abs(stx), aspect='auto')
-    #plt.ylabel('frequency(Hz)')
-    plt.ylabel('strow(f*L/fs)')
-    return ax2
-    

File stockwell/plots.py

+import matplotlib.pyplot as plt
+
+from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, \
+     AnnotationBbox
+
+from mpl_toolkits.axes_grid1 import host_subplot
+
+def plotspec(psx, fs=2.0, lofreq=None, hifreq=None, t1=None, t2=None):
+    """
+    useful for plotting the power of a stockwell transform
+    it relies upon matplotlib for display
+    example:
+    # for a signal x, with sampling frequency 200
+    >>> import stockwell, pylab
+    >>> import stockwell.plots as plots
+    >>> x = pylab.zeros(1000.0) # 5 seconds
+    >>> fs = 200 # sample rate
+    >>> x[250:350] = 1.0 # step function
+    >>> sx = stockwell.st(x)
+    >>> psx = abs(sx) # create power
+    >>> r=plots.plotspec(psx,200)
+    >>> # pylab.show() # to visualize this
+    """
+    extent = [0,psx.shape[1], 0.0, fs/2.0] # default extents
+    if t1 != None and t2 != None:
+        extent[0] = t1
+        extent[1] = t2
+    if lofreq != None:
+        extent[2] = lofreq
+    if hifreq != None:
+        extent[3] = hifreq
+    
+    return plt.imshow(psx, extent=extent, aspect='auto', origin='lower')
+
+
+
+def stpowerstack(x,stx):
+    """
+    need to add row labels
+    """
+    ax1=host_subplot(211)
+    plt.plot(x)
+    ax2 = host_subplot(212)
+    #pax2 = ax2.twinx()
+    #pax2.set_ylabel('frequency(Hz)')
+    plt.imshow(abs(stx), aspect='auto')
+    plt.ylabel('frequency(Hz)')
+    ylocs,ylabels = yticks()
+    #plt.ylabel('st-row(f*L/fs)')
+    yt,xt = stx.shape
+
+
+    return ax2
+    
+if __name__ == "__main__":
+    import doctest
+    doctest.testmod()