示例#1
0
def test_show_vispy():
    """Some basic tests of show_vispy"""
    if has_matplotlib():
        n = 200
        t = np.arange(n)
        noise = np.random.RandomState(0).randn(n)
        # Need, image, markers, line, axes, figure
        plt.figure()
        ax = plt.subplot(211)
        ax.imshow(read_png(load_data_file('pyplot/logo.png')))
        ax = plt.subplot(212)
        ax.plot(t, noise, 'ko-')
        plt.draw()
        canvases = plt.show()
        canvases[0].close()
    else:
        assert_raises(ImportError, plt.show)
示例#2
0
from vispy.io import read_png, load_data_file

n = 200
freq = 10
fs = 100.
t = np.arange(n) / fs
tone = np.sin(2*np.pi*freq*t)
noise = np.random.RandomState(0).randn(n)
signal = tone + noise
magnitude = np.abs(np.fft.fft(signal))
freqs = np.fft.fftfreq(n, 1. / fs)
flim = n // 2

# Signal
fig = plt.figure()
ax = plt.subplot(311)
ax.imshow(read_png(load_data_file('pyplot/logo.png')))

ax = plt.subplot(312)
ax.plot(t, signal, 'k-')

# Frequency content
ax = plt.subplot(313)
idx = np.argmax(magnitude[:flim])
ax.text(freqs[idx], magnitude[idx], 'Max: %s Hz' % freqs[idx],
        verticalalignment='top')
ax.plot(freqs[:flim], magnitude[:flim], 'r-o')

plt.draw()
示例#3
0
文件: mpl_plot.py 项目: kod3r/vispy
import vispy.mpl_plot as plt
from vispy.io import read_png, load_data_file

n = 200
freq = 10
fs = 100.
t = np.arange(n) / fs
tone = np.sin(2 * np.pi * freq * t)
noise = np.random.RandomState(0).randn(n)
signal = tone + noise
magnitude = np.abs(np.fft.fft(signal))
freqs = np.fft.fftfreq(n, 1. / fs)
flim = n // 2

# Signal
fig = plt.figure()
ax = plt.subplot(311)
ax.imshow(read_png(load_data_file('pyplot/logo.png')))

ax = plt.subplot(312)
ax.plot(t, signal, 'k-')

# Frequency content
ax = plt.subplot(313)
idx = np.argmax(magnitude[:flim])
ax.text(freqs[idx],
        magnitude[idx],
        'Max: %s Hz' % freqs[idx],
        verticalalignment='top')
ax.plot(freqs[:flim], magnitude[:flim], 'k-o')
print("... interpolated in %0.2f s using %0.2f MB" %(t2 - t1, mem[-1]))

#==============================================================================
# Write resampled data to WAV-File
#==============================================================================
wavfile.write(file_o, rate_o, data_o.astype('int32'))

###############################################################################
# Plot the data
###############################################################################
#
# Time Domain: Input / output samples and amplitude / time difference
#==============================================================================
#plt.close('all') # large plots = lots of memory ...
if PLT_ENB:
    fig1 = plt.figure(1)
    if PLT_ERR:
        ax1 = fig1.add_subplot(211)
    else:
        ax1 = fig1.add_subplot(111)
        ax1.set_xlabel(t_label)
    ax1.set_ylabel(r'Sample Amplitude $\rightarrow$')
    ax1.plot(time_i[PLT_BEG:PLT_END], data_i[:,0][PLT_BEG:PLT_END], 
     'ro', linestyle = ':', label = 'Original')     
    if PLT_JITTER:
    # Plot resampled data against ORIGINAL time vector time_i to show 
    # the time displacement (jitter)         
        ax1.step(time_i[r*PLT_BEG:r*PLT_END], 
             data_o[:,0][r*PLT_BEG:r*PLT_END], 
             'o', where='post', linestyle = '--', label = 'w/ Jitter',
             color = (0.,0.,1,0.5), markerfacecolor=(0.,0.,1,0.5))