How to use the gr.setwindow 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 / qtgr / __init__.py View on Github external
if logXinDomain != self._logXinDomain:
                self._logXinDomain = logXinDomain
                self.logXinDomain.emit(self._logXinDomain)
            if logYinDomain != self._logYinDomain:
                self._logYinDomain = logYinDomain
                self.logYinDomain.emit(self._logYinDomain)

        if self._pickEvent:
            event = self._pickEvent
            gr.setviewport(*event.viewportscaled)
            wcPoint = event.getWC(event.viewport)
            window = gr.inqwindow()
            gr.setwindow(*event.getWindow())
            gr.setmarkertype(gr.MARKERTYPE_PLUS)
            gr.polymarker([wcPoint.x], [wcPoint.y])
            gr.setwindow(*window)
github sciapp / gr / examples / spectrum.py View on Github external
if mic is None:
        pa = pyaudio.PyAudio()
        mic = pa.open(format=pyaudio.paInt16, channels=1, rate=FS,
                      input=True, frames_per_buffer=SAMPLES)
    amplitudes = numpy.fromstring(mic.read(SAMPLES), dtype=numpy.short)
    return abs(numpy.fft.fft(amplitudes / 32768.0))[:SAMPLES/2]

def parabolic(x, f, i):
    xe = 1/2. * (f[i-1] - f[i+1]) / (f[i-1] - 2 * f[i] + f[i+1]) + x
    ye = f[i] - 1/4. * (f[i-1] - f[i+1]) * (xe - x)
    return xe, ye

f = [FS/float(SAMPLES)*t for t in range(0, SAMPLES//2)]

gr.setviewport(0.1, 0.95, 0.1, 0.95)
gr.setwindow(50, 25000, 0, 100)
gr.setscale(1)

start = time.time()

while time.time() - start < 10:
    try:
        power = get_spectrum()
        peakind = signal.find_peaks_cwt(power, numpy.array([5]))
    except (IOError):
        continue

    gr.clearws()
    gr.setlinewidth(1)
    gr.setlinecolorind(1)
    gr.grid(1, 5, 50, 0, 1, 2)
    gr.axes(1, 5, 50, 0, 1, 2, -0.008)
github sciapp / python-gr / examples / mri.py View on Github external
def draw_image(self):
        if not self.needs_refresh:
            return
        self.needs_refresh = False
        gr.clearws()
        gr.setwindow(0, self.w, 0, self.h)
        gr.setviewport(0, 1, 0, 1)

        gr3.setbackgroundcolor(1, 1, 1, 0)
        vertices, normals = gr3.triangulate(data, (1.0/64, 1.0/64, 1.0/128), (-0.5, -0.5, -0.5), self.isolevel)
        mesh = gr3.createmesh(len(vertices)*3, vertices, normals, np.ones(vertices.shape))
        gr3.drawmesh(mesh, 1, (0,0,0), (0,0,1), (0,1,0), (1,1,1), (1,1,1))
        center = spherical_to_cartesian(-2, np.pi*self.y / self.h+np.pi/2, np.pi*self.x / self.w)
        up = spherical_to_cartesian(1, np.pi*self.y / self.h+np.pi, np.pi*self.x / self.w)
        gr3.cameralookat(center[0], center[1], -0.25+center[2], 0, 0, -0.25, up[0], up[1], up[2])
        gr3.drawimage(0, self.w, 0, self.h, self.w, self.h, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
        if self.export:
            gr3.export("mri.html", 800, 800)
            print("Saved current isosurface to mri.html")
            self.export = False
        gr3.clear()
        gr3.deletemesh(c_int(mesh.value))
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

        gr.setcharheight(charHeight)
        gr.setcharup(*self.charup)
        gr.settextalign(self.halign, self.valign)
        gr.settextpath(self.textpath)
        gr.setcharexpan(self.charexpan)
        if self._font is not None and self._precision is not None:
            gr.settextfontprec(self._font, self._precision)

        tbx, tby = gr.inqtext(x, y, self.text)

        if self._axes:
            gr.setviewport(*self._axes.viewportscaled)
github sciapp / python-gr / gr / pygr / mlab.py View on Github external
vp_aspect = (vp[1] - vp[0]) / (vp[3] - vp[2])
        vp_aspect = vp_aspect / viewport_aspect
        width = (bbox[1] - bbox[0]) / vp_aspect
        height = bbox[3] - bbox[2]
        aspect = width / height
        if aspect > 1:
            d = (width - height) / 2
            bbox[3] += d
            bbox[2] -= d
        else:
            d = (height - width) / 2
            bbox[1] += d
            bbox[0] -= d
        gr.setwindow(*bbox)
    else:
        gr.setwindow(x_min, x_max, y_min, y_max)

    if kind in ('wireframe', 'surface', 'plot3', 'scatter3', 'trisurf', 'volume'):
        z_min, z_max = _plt.kwargs['zrange']
        if not scale & gr.OPTION_Z_LOG:
            if _plt.kwargs.get('adjust_zlim', True):
                z_min, z_max = gr.adjustlimits(z_min, z_max)
            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
github sciapp / gr / examples / pygrwidgetpyside_ex.py View on Github external
def draw(self):
        if not self._draw_graphics:
            return

        x = range(0, 128)
        y = range(0, 128)
        z = readfile(os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                  "kws.dat"), separator='$')
        zrange = max(z) - min(z)
        h = [min(z) + i * 0.025 * zrange for i in range(0, 40)]

        gr.setviewport(0.075, 0.95, 0.075, 0.95)
        gr.setwindow(1, 128, 1, 128)
        gr.setspace(min(z), max(z), 0, 90)
        gr.setcharheight(0.018)
        gr.setcolormap(-3)
        gr.surface(x, y, z, 5)
        gr.contour(x, y, h, z, -1)
        gr.axes(5, 5, 1, 1, 2, 2, 0.0075)
github sciapp / python-gr / gr / pygr / mlab.py View on Github external
vp = _plt.kwargs['vp']
        viewport_aspect = (viewport[1] - viewport[0]) / (viewport[3] - viewport[2])
        vp_aspect = (vp[1] - vp[0]) / (vp[3] - vp[2])
        vp_aspect = vp_aspect / viewport_aspect
        width = (bbox[1] - bbox[0]) / vp_aspect
        height = bbox[3] - bbox[2]
        aspect = width / height
        if aspect > 1:
            d = (width - height) / 2
            bbox[3] += d
            bbox[2] -= d
        else:
            d = (height - width) / 2
            bbox[1] += d
            bbox[0] -= d
        gr.setwindow(*bbox)
    else:
        gr.setwindow(x_min, x_max, y_min, y_max)

    if kind in ('wireframe', 'surface', 'plot3', 'scatter3', 'trisurf', 'volume'):
        z_min, z_max = _plt.kwargs['zrange']
        if not scale & gr.OPTION_Z_LOG:
            if _plt.kwargs.get('adjust_zlim', True):
                z_min, z_max = gr.adjustlimits(z_min, z_max)
            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)
github sciapp / python-gr / examples / mandel_gr3.py View on Github external
x = -0.9223327810370947027656057193752719757635
y = 0.3102598350874576432708737495917724836010

f = 0.5
for i in range(200):
    start = timer()
    pixels = create_fractal(x-f, x+f, y-f, y+f, 500, 500, 400)
    dt = timer() - start

    print("Mandelbrot created in %f s" % dt)

    gr.clearws()
    gr.setviewport(0, 1, 0, 1)
    gr.setcolormap(113)
    z = np.resize(pixels, (500, 500))
    gr.setwindow(0, 500, 0, 500)
    gr.setspace(0, 600, 30, 80)
    gr3.surface(range(500), range(500), z, 3)
    gr.updatews()

    f *= 0.9
github sciapp / gr / examples / mandel_gr3.py View on Github external
x = -0.9223327810370947027656057193752719757635
y = 0.3102598350874576432708737495917724836010

f = 0.5
for i in range(200):
    start = timer()
    pixels = create_fractal(x-f, x+f, y-f, y+f, 500, 500, 400)
    dt = timer() - start

    print("Mandelbrot created in %f s" % dt)

    gr.clearws()
    gr.setviewport(0, 1, 0, 1)
    gr.setcolormap(113)
    z = np.resize(pixels, (500, 500))
    gr.setwindow(0, 500, 0, 500)
    gr.setspace(0, 600, 30, 80)
    gr3.surface(range(500), range(500), z, 3)
    gr.updatews()

    f *= 0.9
github sciapp / gr / examples / double_pendulum.py View on Github external
def pendulum(theta, length, mass):
    l = length[0] + length[1]
    gr.clearws()
    gr.setviewport(0, 1, 0, 1)
    gr.setwindow(-l, l, -l, l)
    gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE)
    gr.setmarkercolorind(86)
    pivot = [0, 0.775]                         # draw pivot point
    gr.fillarea(4, [-0.2, 0.2, 0.2, -0.2], [0.75, 0.75, 0.8, 0.8])
    for i in range(2):
        x = [pivot[0], pivot[0] + sin(theta[i]) * length[i]]
        y = [pivot[1], pivot[1] - cos(theta[i]) * length[i]]
        gr.polyline(2, x, y)                   # draw rod
        gr.setmarkersize(3 * mass[i])
        gr.polymarker(1, [x[1]], [y[1]])       # draw bob
        pivot = [x[1], y[1]]
    gr.updatews()
    return