How to use the gr.setscale function in gr

To help you get started, we’ve selected a few gr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sciapp / python-gr / gr / pygr / __init__.py View on Github external
def _getNDCPoly(self):
        poly = []
        if self._poly:
            if self._axes:
                coord = CoordConverter(self._axes.sizex, self._axes.sizey,
                                       self._axes.getWindow())
                gr.setscale(self._axes.scale)
                for pWC in self._poly:
                    coord.setWCforPlotAxes(pWC.x, pWC.y, self._axes)
                    poly.append(coord.getNDC())
            else:
                poly = self._poly
        return poly
github sciapp / gr / examples / audio_ex3.py View on Github external
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
github sciapp / python-gr / gr / pygr / mlab.py View on Github external
def _colorbar(off=0.0, colors=256, label_name='zlabel'):
    global _plt
    gr.savestate()
    viewport = _plt.kwargs['viewport']
    zmin, zmax = _plt.kwargs['zrange']
    gr.setwindow(0, 1, zmin, zmax)
    gr.setviewport(viewport[1] + 0.02 + off, viewport[1] + 0.05 + off,
                   viewport[2], viewport[3])

    if colors == 1:
        data = [1000]
    else:
        data = [1000 + int(255 * i / (colors - 1)) for i in range(colors)]

    gr.setlinecolorind(1)
    gr.setscale(0)
    if _plt.kwargs['scale'] & gr.OPTION_FLIP_Z:
        gr.cellarray(0, 1, zmin, zmax, 1, colors, data)
    else:
        gr.cellarray(0, 1, zmax, zmin, 1, colors, data)
    diag = ((viewport[1] - viewport[0])**2 + (viewport[3] - viewport[2])**2)**0.5
    charheight = max(0.016 * diag, 0.012)
    gr.setcharheight(charheight)
    if _plt.kwargs['scale'] & gr.OPTION_Z_LOG:
        if _plt.kwargs['scale'] & gr.OPTION_FLIP_Z:
            gr.setscale(gr.OPTION_Y_LOG | gr.OPTION_FLIP_Y)
        else:
            gr.setscale(gr.OPTION_Y_LOG)
        gr.axes(0, 2, 1, zmin, 0, 1, 0.005)
    else:
        if _plt.kwargs['scale'] & gr.OPTION_FLIP_Z:
            gr.setscale(gr.OPTION_FLIP_Y)
github sciapp / python-gr / gr / pygr / mlab.py View on Github external
data = [1000]
    else:
        data = [1000 + int(255 * i / (colors - 1)) for i in range(colors)]

    gr.setlinecolorind(1)
    gr.setscale(0)
    if _plt.kwargs['scale'] & gr.OPTION_FLIP_Z:
        gr.cellarray(0, 1, zmin, zmax, 1, colors, data)
    else:
        gr.cellarray(0, 1, zmax, zmin, 1, colors, data)
    diag = ((viewport[1] - viewport[0])**2 + (viewport[3] - viewport[2])**2)**0.5
    charheight = max(0.016 * diag, 0.012)
    gr.setcharheight(charheight)
    if _plt.kwargs['scale'] & gr.OPTION_Z_LOG:
        if _plt.kwargs['scale'] & gr.OPTION_FLIP_Z:
            gr.setscale(gr.OPTION_Y_LOG | gr.OPTION_FLIP_Y)
        else:
            gr.setscale(gr.OPTION_Y_LOG)
        gr.axes(0, 2, 1, zmin, 0, 1, 0.005)
    else:
        if _plt.kwargs['scale'] & gr.OPTION_FLIP_Z:
            gr.setscale(gr.OPTION_FLIP_Y)
        else:
            gr.setscale(0)
        ztick = 0.5 * gr.tick(zmin, zmax)
        gr.axes(0, ztick, 1, zmin, 0, 1, 0.005)
    label = _plt.kwargs.get(label_name, None)
    if label:
        diag = ((viewport[1] - viewport[0])**2 + (viewport[3] - viewport[2])**2)**0.5
        charheight = max(0.018 * diag, 0.012)
        gr.setcharheight(charheight)
        gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_BASE)
github sciapp / python-gr / gr / pygr / mlab.py View on Github external
data = [1000 + int(255 * i / (colors - 1)) for i in range(colors)]

    gr.setlinecolorind(1)
    gr.setscale(0)
    if _plt.kwargs['scale'] & gr.OPTION_FLIP_Z:
        gr.cellarray(0, 1, zmin, zmax, 1, colors, data)
    else:
        gr.cellarray(0, 1, zmax, zmin, 1, colors, data)
    diag = ((viewport[1] - viewport[0])**2 + (viewport[3] - viewport[2])**2)**0.5
    charheight = max(0.016 * diag, 0.012)
    gr.setcharheight(charheight)
    if _plt.kwargs['scale'] & gr.OPTION_Z_LOG:
        if _plt.kwargs['scale'] & gr.OPTION_FLIP_Z:
            gr.setscale(gr.OPTION_Y_LOG | gr.OPTION_FLIP_Y)
        else:
            gr.setscale(gr.OPTION_Y_LOG)
        gr.axes(0, 2, 1, zmin, 0, 1, 0.005)
    else:
        if _plt.kwargs['scale'] & gr.OPTION_FLIP_Z:
            gr.setscale(gr.OPTION_FLIP_Y)
        else:
            gr.setscale(0)
        ztick = 0.5 * gr.tick(zmin, zmax)
        gr.axes(0, ztick, 1, zmin, 0, 1, 0.005)
    label = _plt.kwargs.get(label_name, None)
    if label:
        diag = ((viewport[1] - viewport[0])**2 + (viewport[3] - viewport[2])**2)**0.5
        charheight = max(0.018 * diag, 0.012)
        gr.setcharheight(charheight)
        gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_BASE)
        gr.textext(viewport[1] + 0.035 + off, viewport[3] + 0.01, label)
    gr.restorestate()
github sciapp / gr / examples / spectrum3.py View on Github external
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
github sciapp / gr / lib / gr / python / gr / pygr.py View on Github external
ymin, ymax = (min(y), max(y))
    else:
        xmin, xmax, ymin, ymax = window
    if scale & gr.OPTION_X_LOG == 0:
        majorx = 5
        xtick = gr.tick(xmin, xmax) / majorx
    else:
        xtick = majorx = 1
    if scale & gr.OPTION_Y_LOG == 0:
        majory = 5
        ytick = gr.tick(ymin, ymax) /majory 
    else:
        ytick = majory = 1
    gr.setviewport(viewport[0], viewport[1], viewport[2], viewport[3])
    gr.setwindow(xmin, xmax, ymin, ymax)
    gr.setscale(scale)
    if bgcolor != 0:
        gr.setfillintstyle(1)
        gr.setfillcolorind(bgcolor)
        gr.fillrect(xmin, xmax, ymin, ymax)
    charheight = 0.024 * (viewport[3] - viewport[2])
    gr.setcharheight(charheight)
    gr.axes(xtick, ytick, xmin, ymin,  majorx,  majory,  0.01)
    gr.axes(xtick, ytick, xmax, ymax, -majorx, -majory, -0.01)
    if grid:
         gr.grid(xtick, ytick, xmax, ymax, majorx, majory)
    gr.setlinetype(linetype)
    gr.polyline(n, x, y)
    if markertype != gr.MARKERTYPE_DOT:
        gr.setmarkertype(markertype)
        gr.polymarker(n, x, y)
    if update:
github sciapp / gr / lib / gr / python / gr / pygr / __init__.py View on Github external
def getBoundingBox(self):
        if self._axes:
            gr.setscale(self._axes.scale)
            coord = CoordConverter(self._axes.sizex, self._axes.sizey,
                                   self._axes.getWindow())
            coord.setWCforPlotAxes(self.x, self.y, self._axes)
            p0 = coord.getNDC()
            x, y = p0.x, p0.y

            charHeight = self.charheight * self._axes.sizey
            window = gr.inqwindow()
            # set viewport and window to NDC to allow 'line-drawing'
            # in all regions and in NDC coordinates
            # if hideviewport is False.
            gr.setviewport(0, self._axes.sizex, 0, self._axes.sizey)
            gr.setwindow(0, self._axes.sizex, 0, self._axes.sizey)
        else:
            x, y = self.x, self.y
            charHeight = self.charheight
github sciapp / python-gr / examples / spectrum3.py View on Github external
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
github sciapp / python-gr / gr / pygr / mlab.py View on Github external
z_major_count = major_count
            z_tick = gr.tick(z_min, z_max) / z_major_count
        else:
            z_tick = z_major_count = 1
        if not scale & gr.OPTION_FLIP_Z:
            zorg = (z_min, z_max)
        else:
            zorg = (z_max, z_min)
        _plt.kwargs['zaxis'] = z_tick, zorg, z_major_count

        rotation = _plt.kwargs.get('rotation', 40)
        tilt = _plt.kwargs.get('tilt', 70)
        gr.setspace(z_min, z_max, rotation, tilt)

    _plt.kwargs['scale'] = scale
    gr.setscale(scale)