Esempio n. 1
0
def _draw_axes(kind, pass_=1):
    global _plt
    viewport = _plt.kwargs['viewport']
    vp = _plt.kwargs['vp']
    x_tick, x_org, x_major_count = _plt.kwargs['xaxis']
    y_tick, y_org, y_major_count = _plt.kwargs['yaxis']

    gr.setlinecolorind(1)
    gr.setlinewidth(1)
    diag = ((viewport[1]-viewport[0])**2 + (viewport[3]-viewport[2])**2)**0.5
    charheight = max(0.018 * diag, 0.012)
    gr.setcharheight(charheight)
    ticksize = 0.0075 * diag
    if kind in ('wireframe', 'surface', 'plot3', 'scatter3', 'trisurf'):
        z_tick, z_org, z_major_count = _plt.kwargs['zaxis']
        if pass_ == 1:
            gr.grid3d(x_tick, 0, z_tick, x_org[0], y_org[1], z_org[0], 2, 0, 2)
            gr.grid3d(0, y_tick, 0, x_org[0], y_org[1], z_org[0], 0, 2, 0)
        else:
            gr.axes3d(x_tick, 0, z_tick, x_org[0], y_org[0], z_org[0], x_major_count, 0, z_major_count, -ticksize)
            gr.axes3d(0, y_tick, 0, x_org[1], y_org[0], z_org[0], 0, y_major_count, 0, ticksize)
    else:
        if kind == 'heatmap':
            ticksize = -ticksize
        else:
            gr.grid(x_tick, y_tick, 0, 0, x_major_count, y_major_count)
        gr.axes(x_tick, y_tick, x_org[0], y_org[0], x_major_count, y_major_count, ticksize)
        gr.axes(x_tick, y_tick, x_org[1], y_org[1], -x_major_count, -y_major_count, -ticksize)

    if 'title' in _plt.kwargs:
        gr.savestate()
        gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP)
        gr.textext(0.5*(viewport[0] + viewport[1]), vp[3], _plt.kwargs['title'])
        gr.restorestate()

    if kind in ('wireframe', 'surface', 'plot3', 'scatter3', 'trisurf'):
        x_label = _plt.kwargs.get('xlabel', '')
        y_label = _plt.kwargs.get('ylabel', '')
        z_label = _plt.kwargs.get('zlabel', '')
        gr.titles3d(x_label, y_label, z_label)
    else:
        if 'xlabel' in _plt.kwargs:
            gr.savestate()
            gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_BOTTOM)
            gr.textext(0.5 * (viewport[0] + viewport[1]), vp[2] + 0.5 * charheight, _plt.kwargs['xlabel'])
            gr.restorestate()
        if 'ylabel' in _plt.kwargs:
            gr.savestate()
            gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP)
            gr.setcharup(-1, 0)
            gr.textext(vp[0] + 0.5 * charheight, 0.5 * (viewport[2] + viewport[3]), _plt.kwargs['ylabel'])
            gr.restorestate()
Esempio n. 2
0
def _draw_axes(kind, pass_=1):
    global _plt
    viewport = _plt.kwargs['viewport']
    vp = _plt.kwargs['vp']
    x_tick, x_org, x_major_count = _plt.kwargs['xaxis']
    y_tick, y_org, y_major_count = _plt.kwargs['yaxis']

    gr.setlinecolorind(1)
    gr.setlinewidth(1)
    diag = ((viewport[1]-viewport[0])**2 + (viewport[3]-viewport[2])**2)**0.5
    charheight = max(0.018 * diag, 0.012)
    gr.setcharheight(charheight)
    ticksize = 0.0075 * diag
    if kind in ('wireframe', 'surface', 'plot3', 'scatter3', 'trisurf'):
        z_tick, z_org, z_major_count = _plt.kwargs['zaxis']
        if pass_ == 1:
            gr.grid3d(x_tick, 0, z_tick, x_org[0], y_org[0], z_org[0], 2, 0, 2)
            gr.grid3d(0, y_tick, 0, x_org[1], y_org[0], z_org[0], 0, 2, 0)
        else:
            gr.axes3d(x_tick, 0, z_tick, x_org[0], y_org[0], z_org[0], x_major_count, 0, z_major_count, -ticksize)
            gr.axes3d(0, y_tick, 0, x_org[1], y_org[0], z_org[0], 0, y_major_count, 0, ticksize)
    else:
        if kind == 'heatmap':
            ticksize = -ticksize
        else:
            gr.grid(x_tick, y_tick, 0, 0, x_major_count, y_major_count)
        gr.axes(x_tick, y_tick, x_org[0], y_org[0], x_major_count, y_major_count, ticksize)
        gr.axes(x_tick, y_tick, x_org[1], y_org[1], -x_major_count, -y_major_count, -ticksize)

    if 'title' in _plt.kwargs:
        gr.savestate()
        gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP)
        gr.textext(0.5*(viewport[0] + viewport[1]), vp[3], _plt.kwargs['title'])
        gr.restorestate()

    if kind in ('wireframe', 'surface', 'plot3', 'scatter3', 'trisurf'):
        x_label = _plt.kwargs.get('xlabel', '')
        y_label = _plt.kwargs.get('ylabel', '')
        z_label = _plt.kwargs.get('zlabel', '')
        gr.titles3d(x_label, y_label, z_label)
    else:
        if 'xlabel' in _plt.kwargs:
            gr.savestate()
            gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_BOTTOM)
            gr.textext(0.5 * (viewport[0] + viewport[1]), vp[2] + 0.5 * charheight, _plt.kwargs['xlabel'])
            gr.restorestate()
        if 'ylabel' in _plt.kwargs:
            gr.savestate()
            gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP)
            gr.setcharup(-1, 0)
            gr.textext(vp[0] + 0.5 * charheight, 0.5 * (viewport[2] + viewport[3]), _plt.kwargs['ylabel'])
            gr.restorestate()
Esempio n. 3
0
 def draw(self):
     gr.clearws()
     gr.setwswindow(0, self._sizex, 0, self._sizey)
     gr.setviewport(0, self._sizex, 0, self._sizey)
     if self._projection == 'perspective':
         gr.setperspectiveprojection(near_plane=0.1, far_plane=1000, fov=15)
     else:
         gr.setorthographicprojection(left=-60,
                                      right=60,
                                      bottom=-60,
                                      top=60,
                                      near_plane=-60,
                                      far_plane=60)
     gr.axes3d(10, 10, 10, 50, 50, 0, 2, 2, 2, -0.0075)
     self.update()
Esempio n. 4
0
spectrum = np.zeros((256, 256), dtype=float)
t = -255
dt = float(SAMPLES) / FS
df = FS / float(SAMPLES) / 2 / 2

start = time.time()

while time.time() - start < 10:
    try:
        power = get_spectrum()
    except (IOError):
        continue

    gr.clearws()
    spectrum[:, 255] = power[:256]
    spectrum = np.roll(spectrum, 1)
    gr.setcolormap(-113)
    gr.setviewport(0.05, 0.95, 0.1, 1)
    gr.setwindow(t * dt, (t + 255) * dt, 0, df)
    gr.setscale(gr.OPTION_FLIP_X)
    gr.setspace(0, 200, 30, 80)
    gr3.surface((t + np.arange(256)) * dt, np.linspace(0, df, 256), spectrum,
                4)
    gr.setscale(0)
    gr.axes3d(0.2, 0.2, 0, (t + 255) * dt, 0, 0, 5, 5, 0, -0.01)
    gr.titles3d('t [s]', 'f [kHz]', '')
    gr.updatews()

    t += 1
Esempio n. 5
0
    return abs(np.fft.fft(amplitudes / 32768.0))[:SAMPLES/2]

spectrum = np.zeros((256, 256), dtype=float)
t = -255
dt = float(SAMPLES) / FS
df = FS / float(SAMPLES) / 2 / 2

start = time.time()

while time.time() - start < 10:
    try:
        power = get_spectrum()
    except (IOError):
        continue

    gr.clearws()
    spectrum[:, 255] = power[:256]
    spectrum = np.roll(spectrum, 1)
    gr.setcolormap(-113)
    gr.setviewport(0.05, 0.95, 0.1, 1)
    gr.setwindow(t * dt, (t + 255) * dt, 0, df)
    gr.setscale(gr.OPTION_FLIP_X)
    gr.setspace(0, 200, 30, 80)
    gr3.surface((t + np.arange(256)) * dt, np.linspace(0, df, 256), spectrum, 4)
    gr.setscale(0)
    gr.axes3d(0.2, 0.2, 0, (t + 255) * dt, 0, 0, 5, 5, 0, -0.01)
    gr.titles3d('t [s]', 'f [kHz]', '')
    gr.updatews()

    t += 1
Esempio n. 6
0
stream = pa.open(format=pa.get_format_from_width(wf.getsampwidth()),
                 channels=wf.getnchannels(), rate=wf.getframerate(), output=True)

spectrum = np.zeros((256, 64), dtype=float)
t = -63
dt = float(SAMPLES) / FS
df = FS / float(SAMPLES) / 2 / 2

data = wf.readframes(SAMPLES)
while data != '' and len(data) == SAMPLES * wf.getsampwidth():
    stream.write(data)
    amplitudes = np.fromstring(data, dtype=np.short)
    power = abs(np.fft.fft(amplitudes / 32768.0))[:SAMPLES/2]

    gr.clearws()
    spectrum[:, 63] = power[:256]
    spectrum = np.roll(spectrum, 1)
    gr.setcolormap(-113)
    gr.setviewport(0.05, 0.95, 0.1, 1)
    gr.setwindow(t * dt, (t + 63) * dt, 0, df)
    gr.setscale(gr.OPTION_FLIP_X)
    gr.setspace(0, 256, 30, 80)
    gr3.surface((t + np.arange(64)) * dt, np.linspace(0, df, 256), spectrum, 4)
    gr.setscale(0)
    gr.axes3d(0.2, 0.2, 0, (t + 63) * dt, 0, 0, 5, 5, 0, -0.01)
    gr.titles3d('t [s]', 'f [kHz]', '')
    gr.updatews()

    data = wf.readframes(SAMPLES)
    t += 1
Esempio n. 7
0
                 rate=wf.getframerate(),
                 output=True)

spectrum = np.zeros((256, 64), dtype=float)
t = -63
dt = float(SAMPLES) / FS
df = FS / float(SAMPLES) / 2 / 2

data = wf.readframes(SAMPLES)
while data != '' and len(data) == SAMPLES * wf.getsampwidth():
    stream.write(data)
    amplitudes = np.frombuffer(data, dtype=np.short)
    power = abs(np.fft.fft(amplitudes / 32768.0))[:SAMPLES // 2]

    gr.clearws()
    spectrum[:, 63] = power[:256]
    spectrum = np.roll(spectrum, 1)
    gr.setcolormap(-113)
    gr.setviewport(0.05, 0.95, 0.1, 1)
    gr.setwindow(t * dt, (t + 63) * dt, 0, df)
    gr.setscale(gr.OPTION_FLIP_X)
    gr.setspace(0, 256, 30, 80)
    gr3.surface((t + np.arange(64)) * dt, np.linspace(0, df, 256), spectrum, 4)
    gr.setscale(0)
    gr.axes3d(0.2, 0.2, 0, (t + 63) * dt, 0, 0, 5, 5, 0, -0.01)
    gr.titles3d('t [s]', 'f [kHz]', '')
    gr.updatews()

    data = wf.readframes(SAMPLES)
    t += 1
Esempio n. 8
0
x = [-2 + i * 0.5 for i in range(0, 29)]
y = [-7 + i * 0.5 for i in range(0, 29)]
z = list(range(0, 841))

for i in range(0, 29):
    for j in range(0, 29):
        r1 = math.sqrt((x[j] - 5)**2 + y[i]**2)
        r2 = math.sqrt((x[j] + 5)**2 + y[i]**2)
        z[i * 29 - 1 +
          j] = (math.exp(math.cos(r1)) + math.exp(math.cos(r2)) - 0.9) * 25

gr.setcharheight(24.0 / 500)
gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP)
gr.textext(0.5, 0.9, "Surface Example")
(tbx, tby) = gr.inqtextext(0.5, 0.9, "Surface Example")
gr.fillarea(tbx, tby)

gr.setwindow(-2, 12, -7, 7)
gr.setspace(-80, 200, 45, 70)

gr.setcharheight(14.0 / 500)
gr.axes3d(1, 0, 20, -2, -7, -80, 2, 0, 2, -0.01)
gr.axes3d(0, 1, 0, 12, -7, -80, 0, 2, 0, 0.01)
gr.titles3d("X-Axis", "Y-Axis", "Z-Axis")

gr.surface(x, y, z, 3)
gr.surface(x, y, z, 1)

gr.updatews()