From: W. Trevor King Date: Sun, 18 Nov 2012 21:39:39 +0000 (-0500) Subject: FFT_tools: cleanup namespace by using _pyplot X-Git-Tag: 0.4~14 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=79f80e17bbb2952a5b8ac28cfcf91f86e82b2a74;p=FFT-tools.git FFT_tools: cleanup namespace by using _pyplot --- diff --git a/FFT_tools.py b/FFT_tools.py index 3383c08..1c3455f 100644 --- a/FFT_tools.py +++ b/FFT_tools.py @@ -207,15 +207,15 @@ def _test_unitary_rfft_rect(a=1.0, time_shift=5.0, samp_freq=25.6, samples=256) expected[i] = 1.0/_numpy.abs(a) * _numpy.sinc(f/a) if TEST_PLOTS : - pylab.figure() - pylab.subplot(211) - pylab.plot(_numpy.arange(0, dt*samples, dt), x) - pylab.title('time series') - pylab.subplot(212) - pylab.plot(freq_axis, X.real, 'r.') - pylab.plot(freq_axis, X.imag, 'g.') - pylab.plot(freq_axis, expected, 'b-') - pylab.title('freq series') + figure = _pyplot.figure() + time_axes = figure.add_subplot(2, 1, 1) + time_axes.plot(_numpy.arange(0, dt*samples, dt), x) + time_axes.set_title('time series') + freq_axes = figure.add_subplot(2, 1, 2) + freq_axes.plot(freq_axis, X.real, 'r.') + freq_axes.plot(freq_axis, X.imag, 'g.') + freq_axes.plot(freq_axis, expected, 'b-') + freq_axes.set_title('freq series') def _test_unitary_rfft_rect_suite() : print('Test unitary FFTs on variously shaped rectangular functions') @@ -255,15 +255,15 @@ def _test_unitary_rfft_gaussian(a=1.0, time_shift=5.0, samp_freq=25.6, samples=2 1.0/a, _numpy.pi*f) if TEST_PLOTS : - pylab.figure() - pylab.subplot(211) - pylab.plot(_numpy.arange(0, dt*samples, dt), x) - pylab.title('time series') - pylab.subplot(212) - pylab.plot(freq_axis, X.real, 'r.') - pylab.plot(freq_axis, X.imag, 'g.') - pylab.plot(freq_axis, expected, 'b-') - pylab.title('freq series') + figure = _pyplot.figure() + time_axes = figure.add_subplot(2, 1, 1) + time_axes.plot(_numpy.arange(0, dt*samples, dt), x) + time_axes.set_title('time series') + freq_axes = figure.add_subplot(2, 1, 2) + freq_axes.plot(freq_axis, X.real, 'r.') + freq_axes.plot(freq_axis, X.imag, 'g.') + freq_axes.plot(freq_axis, expected, 'b-') + freq_axes.set_title('freq series') def _test_unitary_rfft_gaussian_suite() : print("Test unitary FFTs on variously shaped gaussian functions") @@ -366,14 +366,16 @@ def _test_unitary_power_spectrum_sin(sin_freq=10, samp_freq=512, samples=1024) : print('The total power should be {} ({})'.format(Pexp, P)) if TEST_PLOTS : - pylab.figure() - pylab.subplot(211) - pylab.plot(_numpy.arange(0, samples/samp_freq, 1.0/samp_freq), x, 'b-') - pylab.title('time series') - pylab.subplot(212) - pylab.plot(freq_axis, power, 'r.') - pylab.plot(freq_axis, expected, 'b-') - pylab.title('{} samples of sin at {} Hz'.format(samples, sin_freq)) + figure = _pyplot.figure() + time_axes = figure.add_subplot(2, 1, 1) + time_axes.plot( + _numpy.arange(0, samples/samp_freq, 1.0/samp_freq), x, 'b-') + time_axes.set_title('time series') + freq_axes = figure.add_subplot(2, 1, 2) + freq_axes.plot(freq_axis, power, 'r.') + freq_axes.plot(freq_axis, expected, 'b-') + freq_axes.set_title( + '{} samples of sin at {} Hz'.format(samples, sin_freq)) def _test_unitary_power_spectrum_sin_suite() : print('Test unitary power spectrums on variously shaped sin functions') @@ -412,14 +414,15 @@ def _test_unitary_power_spectrum_delta(amp=1, samp_freq=1, samples=256) : expected_amp, power[0])) if TEST_PLOTS : - pylab.figure() - pylab.subplot(211) - pylab.plot(_numpy.arange(0, samples/samp_freq, 1.0/samp_freq), x, 'b-') - pylab.title('time series') - pylab.subplot(212) - pylab.plot(freq_axis, power, 'r.') - pylab.plot(freq_axis, expected, 'b-') - pylab.title('{} samples of delta amp {}'.format(samples, amp)) + figure = _pyplot.figure() + time_axes = figure.add_subplot(2, 1, 1) + time_axes.plot( + _numpy.arange(0, samples/samp_freq, 1.0/samp_freq), x, 'b-') + time_axes.set_title('time series') + freq_axes = figure.add_subplot(2, 1, 2) + freq_axes.plot(freq_axis, power, 'r.') + freq_axes.plot(freq_axis, expected, 'b-') + freq_axes.set_title('{} samples of delta amp {}'.format(samples, amp)) def _test_unitary_power_spectrum_delta_suite() : print('Test unitary power spectrums on various delta functions') @@ -469,14 +472,15 @@ def _test_unitary_power_spectrum_gaussian(area=2.5, mean=5, std=1, samp_freq=10. expected[0], power[0])) if TEST_PLOTS : - pylab.figure() - pylab.subplot(211) - pylab.plot(_numpy.arange(0, samples/samp_freq, 1.0/samp_freq), x, 'b-') - pylab.title('time series') - pylab.subplot(212) - pylab.plot(freq_axis, power, 'r.') - pylab.plot(freq_axis, expected, 'b-') - pylab.title('freq series') + figure = _pyplot.figure() + time_axes = figure.add_subplot(2, 1, 1) + time_axes.plot( + _numpy.arange(0, samples/samp_freq, 1.0/samp_freq), x, 'b-') + time_axes.set_title('time series') + freq_axes = figure.add_subplot(2, 1, 2) + freq_axes.plot(freq_axis, power, 'r.') + freq_axes.plot(freq_axis, expected, 'b-') + freq_axes.set_title('freq series') def _test_unitary_power_spectrum_gaussian_suite() : print('Test unitary power spectrums on various gaussian functions') @@ -585,14 +589,16 @@ def _test_unitary_avg_power_spectrum_sin(sin_freq=10, samp_freq=512, samples=102 print('The total power should be {} ({})'.format(Pexp, P)) if TEST_PLOTS : - pylab.figure() - pylab.subplot(211) - pylab.plot(_numpy.arange(0, samples/samp_freq, 1.0/samp_freq), x, 'b-') - pylab.title('time series') - pylab.subplot(212) - pylab.plot(freq_axis, power, 'r.') - pylab.plot(freq_axis, expected, 'b-') - pylab.title('{} samples of sin at {} Hz'.format(samples, sin_freq)) + figure = _pyplot.figure() + time_axes = figure.add_subplot(2, 1, 1) + time_axes.plot( + _numpy.arange(0, samples/samp_freq, 1.0/samp_freq), x, 'b-') + time_axes.set_title('time series') + freq_axes = figure.add_subplot(2, 1, 2) + freq_axes.plot(freq_axis, power, 'r.') + freq_axes.plot(freq_axis, expected, 'b-') + freq_axes.set_title( + '{} samples of sin at {} Hz'.format(samples, sin_freq)) def _test_unitary_avg_power_spectrum_sin_suite() : print('Test unitary avg power spectrums on variously shaped sin functions') @@ -628,8 +634,8 @@ if __name__ == '__main__': options,args = p.parse_args() if options.plot: - import pylab + import matplotlib.pyplot as _pyplot TEST_PLOTS = True test() if options.plot: - pylab.show() + _pyplot.show()