@@ -33,12 +33,7 @@ def cwt(input, fs, f0, f1, fn, nthreads=1, scaling="lin", fast=False, norm=True)
3333
3434 return freqs , output
3535
36- def plot (input , fs , f0 = 0 , f1 = 0 , fn = 0 , nthreads = 1 , scaling = "lin" , fast = False , norm = True ):
37-
38- f0 = f0 if f0 else 1 / (input .size / fs )
39- f1 = f1 if f1 else fs / 2
40- fn = fn if fn else 100
41- freqs , output = cwt (input , fs , f0 , f1 , fn , nthreads = nthreads , scaling = scaling , fast = fast , norm = norm )
36+ def _plot (input , freqs , output , fs , f0 , f1 , fn ):
4237
4338 #create two subplots
4439 fig , (ax1 , ax2 ) = plt .subplots (2 , 1 , sharex = True )
@@ -49,14 +44,48 @@ def plot(input, fs, f0=0, f1=0, fn=0, nthreads=1, scaling="lin", fast=False, nor
4944
5045 #plot spectrogram
5146 ax2 .imshow (np .abs (output ),aspect = 'auto' )
47+
5248
5349 #set time on x-axis every 10s and frequency on y-axis for 10 ticks
50+ # So we have fixed 10 ticks on the Y-axis; 10s occupies one X tick
51+
52+ XTickInterval = 10 # Seconds
53+ YTickCount = 9
54+ YLabelDecimalPlaces = 1
55+
5456 ax2 .set_xlabel ('Time (s)' )
5557 ax2 .set_ylabel ('Frequency (Hz)' )
5658 ax2 .set_title ('CWT' )
57- ax2 .set_xticks (np .arange (0 ,input .size ,fs * 10 ),np .arange (0 ,input .size / fs ,10 ))
58- ax2 .set_yticks (np .arange (0 ,fn ,fn / 10 ),np .round (freqs [::int (fn / 10 )]))
59+
60+
61+
62+ yFrequencies = np .linspace (freqs [0 ], freqs [- 1 ], num = YTickCount ) # Select evenly-spaced frequencies, including the highest and lowest
63+
64+
65+ xTickPositions = np . arange (0 , input .size , fs * XTickInterval ) # For X, just stepping in increments is suitable
66+ yTickPositions = np .linspace (0 , fn , num = YTickCount ) # For Y, we want to ensure f0 and f1 are included as ticks.
67+
68+ xLabels = np .arange (0 , input .size / fs , XTickInterval )
69+
70+ # Round the Y labels to be 1 d.p.
71+ yLabels = np . round (yFrequencies , decimals = YLabelDecimalPlaces ) # Will be co-erced to a string for us later.
72+
73+
74+ ax2 .set_xticks ( ticks = xTickPositions , labels = xLabels )
75+ ax2 .set_yticks ( ticks = yTickPositions , labels = yLabels )
5976
6077
6178 plt .show ()
79+
80+
81+ def plot (input , fs , f0 = 0 , f1 = 0 , fn = 0 , nthreads = 1 , scaling = "lin" , fast = False , norm = True ):
82+
83+ f0 = f0 if f0 else 1 / (input .size / fs )
84+ f1 = f1 if f1 else fs / 2
85+ fn = fn if fn else 100
86+ freqs , output = cwt (input , fs , f0 , f1 , fn , nthreads = nthreads , scaling = scaling , fast = fast , norm = norm )
87+
88+ _plot (input , output , fs , f0 , f1 , fn )
89+
90+
6291
0 commit comments