How to use the gr.polyline 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 / gr / lib / gr / python / gr / pygr / mlab.py View on Github external
_set_window(kind)
        if kind == 'polar':
            _draw_polar_axes()
        else:
            _draw_axes(kind)

    gr.setcolormap(_plt.kwargs.get('colormap', gr.COLORMAP_COOLWARM))
    gr.uselinespec(" ")
    for x, y, z, c, spec in _plt.args:
        gr.savestate()
        if 'alpha' in _plt.kwargs:
            gr.settransparency(_plt.kwargs['alpha'])
        if kind == 'line':
            mask = gr.uselinespec(spec)
            if mask in (0, 1, 3, 4, 5):
                gr.polyline(x, y)
            if mask & 2:
                gr.polymarker(x, y)
        elif kind == 'scatter':
            gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE)
            if z is not None or c is not None:
                if c is not None:
                    c_min = c.min()
                    c_ptp = c.ptp()
                for i in range(len(x)):
                    if z is not None:
                        gr.setmarkersize(z[i] / 100.0)
                    if c is not None:
                        c_index = 1000 + int(255 * (c[i]-c_min)/c_ptp)
                        gr.setmarkercolorind(c_index)
                    gr.polymarker([x[i]], [y[i]])
            else:
github sciapp / python-gr / examples / spectrum.py View on Github external
power = get_spectrum()
        peakind = signal.find_peaks_cwt(power, np.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)
    gr.setcharheight(0.020)
    gr.text(0.15, 0.965, '100Hz')
    gr.text(0.47, 0.965, '1kHz')
    gr.text(0.79, 0.965, '10kHz')
    gr.setlinecolorind(4)
    gr.polyline(f[1:], power[1:])
    for p in peakind:
        if power[p] > 10:
            gr.setlinewidth(2)
            gr.setlinecolorind(2)
            xe, ye = parabolic(f[p], power, p)
            print(xe, ye)
            gr.polyline([xe] * 2, [0, ye])
    gr.updatews()
github sciapp / python-gr / examples / pendulum.py View on Github external
def pendulum(t, theta, omega, acceleration):
    gr.clearws()
    gr.setviewport(0, 1, 0, 1)

    x = [0.5, 0.5 + np.sin(theta) * 0.4]
    y = [0.8, 0.8 - np.cos(theta) * 0.4]
    # draw pivot point
    gr.fillarea([0.46, 0.54, 0.54, 0.46], [0.79, 0.79, 0.81, 0.81]),

    gr.setlinecolorind(1)
    gr.setlinewidth(2)
    gr.polyline(x, y)  # draw rod
    gr.setmarkersize(5)
    gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE)
    gr.setmarkercolorind(86)
    gr.polymarker([x[1]], [y[1]])  # draw bob
    gr.setlinecolorind(4)
    V = 0.05 * omega  # show angular velocity
    gr.drawarrow(x[1], y[1], x[1] + V * np.cos(theta), y[1] + V * np.sin(theta))
    gr.setlinecolorind(2)
    A = 0.05 * acceleration  # show angular acceleration
    gr.drawarrow(x[1], y[1], x[1] + A * np.sin(theta), y[1] + A * np.cos(theta))

    gr.settextfontprec(2, gr.TEXT_PRECISION_STRING)
    gr.setcharheight(0.032)
    gr.settextcolorind(1)
    gr.textext(0.05, 0.95, 'Damped Pendulum')
    gr.setcharheight(0.040)
github sciapp / python-gr / gr / pygr / __init__.py View on Github external
if y < 0:
                                    vp = self.viewport
                                    vp[2] += 3 * charHeightUnscaled
                                    # propagate update (calls setter)
                                    self.viewport = vp
                                    redraw = True
                                    break
                            gr.setmarkertype(curve.markertype)
                            gr.setmarkercolorind(curve.markercolor)
                            ys = y * self.sizey # scaled y value
                            if curve.linetype is not None:
                                gr.setlinecolorind(curve.linecolor)
                                gr.setmarkercolorind(curve.markercolor)
                                gr.setlinetype(curve.linetype)
                                gr.setlinewidth(curve.linewidth)
                                gr.polyline([x, x + lineWidth], [ys, ys])
                                if (curve.markertype != gr.MARKERTYPE_DOT
                                    and curve.markertype is not None):
                                    gr.setmarkertype(curve.markertype)
                                    gr.polymarker([x + lineWidth / 2.], [ys])
                            elif curve.markertype is not None:
                                gr.setmarkertype(curve.markertype)
                                gr.polymarker([x + lineWidth / 2.], [ys])

                            ybase = (y - charHeightUnscaled / 2) * self.sizey
                            ytop = (y + charHeightUnscaled / 2) * self.sizey
                            roi = RegionOfInterest(Point(x, ybase),
                                                   Point(x, ytop),
                                                   reference=curve,
                                           regionType=RegionOfInterest.LEGEND)
                            x += lineWidth + .01
                            if curve.visible:
github sciapp / gr / examples / audio_ex.py View on Github external
gr.setviewport(0.05, 0.95, 0.05, 0.95)
gr.setlinecolorind(218)
gr.setfillintstyle(1)
gr.setfillcolorind(208)

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

    gr.clearws()
    gr.fillrect(0, SAMPLES, -30000, 30000)
    gr.grid(40, 1200, 0, 0, 5, 5)
    gr.polyline(SAMPLES/4, range(SAMPLES)[0::4], amplitudes[0::4])
    gr.polyline(SAMPLES/8, range(SAMPLES)[0::8], power)
    gr.updatews()

    data = wf.readframes(SAMPLES)
github sciapp / python-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([-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] + np.sin(theta[i]) * length[i]]
        y = [pivot[1], pivot[1] - np.cos(theta[i]) * length[i]]
        gr.polyline(x, y)                   # draw rod
        gr.setmarkersize(3 * mass[i])
        gr.polymarker([x[1]], [y[1]])       # draw bob
        pivot = [x[1], y[1]]
    gr.updatews()
    return
github sciapp / python-gr / gr / pygr / mlab.py View on Github external
cosf = np.cos(np.radians(angle))
        pline = np.array([r_min / r_max, 1])
        if phi_min <= angle <= phi_max:
            if i % 2 == 0 and not (i == n and phi_max % 360 == phi_min % 360):
                gr.setlinecolorind(88)
                gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_HALF)
                x, y = gr.wctondc(1.1 * cosf, 1.1 * sinf)
                gr.textext(x, y, "%g\xb0" % angle_label)
            else:
                gr.setlinecolorind(90)
        else:
            angle = np.clip(angle, phi_min, phi_max)
            gr.setlinecolorind(88)
            sinf = np.sin(np.radians(angle))
            cosf = np.cos(np.radians(angle))
        gr.polyline(cosf * pline, sinf * pline)
    tick = 0.5 * gr.tick(r_min, r_max)
    n = int(round((r_max - r_min) / tick + 0.5))
    for i in range(n + 1):
        r = (r_min + i * tick) / r_max
        gr.setlinecolorind(88)
        r = np.clip(r, 0, 1)
        if i % 2 == 1 and r <= 1:
            gr.setlinecolorind(90)
        gr.drawarc(-r, r, -r, r, phi_min, phi_max)
        if i % 2 == 0 and not r > 1:
            gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_HALF)
            sinf = np.sin(np.radians(phi_min))
            cosf = np.cos(np.radians(phi_min))
            x, y = gr.wctondc(r * cosf + sinf * 0.05, r * sinf - cosf * 0.05)
            if _plt.kwargs.get('rflip', False):
                r_label = r_max - i * tick
github sciapp / python-gr / gr / pygr / mlab.py View on Github external
else:
            _draw_axes(kind)
    elif kind in ('polar', 'polar_heatmap'):
        _set_viewport(kind, _plt.kwargs['subplot'])
        _set_window(kind)

    _set_colormap()
    gr.uselinespec(" ")
    for x, y, z, c, spec in _plt.args:
        gr.savestate()
        if 'alpha' in _plt.kwargs:
            gr.settransparency(_plt.kwargs['alpha'])
        if kind == 'line':
            mask = gr.uselinespec(spec)
            if mask in (0, 1, 3, 4, 5):
                gr.polyline(x, y)
            if mask & 2:
                gr.polymarker(x, y)
        if kind == 'step':
            mask = gr.uselinespec(spec)
            if mask in (0, 1, 3, 4, 5):
                where = _plt.kwargs.get('step_where', 'mid')
                if where == 'pre':
                    n = len(x)
                    x_step_boundaries = np.zeros(2 * n - 1)
                    y_step_values = np.zeros(2 * n - 1)
                    x_step_boundaries[0] = x[0]
                    x_step_boundaries[1::2] = x[:-1]
                    x_step_boundaries[2::2] = x[1:]
                    y_step_values[0] = y[0]
                    y_step_values[1::2] = y[1:]
                    y_step_values[2::2] = y[1:]
github sciapp / gr / lib / gr / python / gr / pygr / mlab.py View on Github external
py = viewport[3] - 0.06

    gr.setfillintstyle(gr.INTSTYLE_SOLID)
    gr.setfillcolorind(0)
    gr.fillrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * num_lines)
    gr.setlinetype(gr.LINETYPE_SOLID)
    gr.setlinecolorind(1)
    gr.setlinewidth(1)
    gr.drawrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * num_lines)
    i = 0
    gr.uselinespec(" ")
    for (x, y, z, c, spec) in _plt.args:
        gr.savestate()
        mask = gr.uselinespec(spec)
        if mask in (0, 1, 3, 4, 5):
            gr.polyline([px - 0.07, px - 0.01], [py, py])
        if mask & 2:
            gr.polymarker([px - 0.06, px - 0.02], [py, py])
        gr.restorestate()
        gr.settextalign(gr.TEXT_HALIGN_LEFT, gr.TEXT_VALIGN_HALF)
        if i < num_labels:
            gr.textext(px, py, _plt.kwargs['labels'][i])
            i += 1
        py -= 0.03
    gr.selntran(1)
    gr.restorestate()
github sciapp / python-gr / examples / qtgrspectrum.py View on Github external
def drawGR(self):
        if self.linetype is not None and self.x:
            # preserve old values
            lcolor = gr.inqlinecolorind()
            gr.setlinewidth(2)
            gr.setlinecolorind(self.linecolor)

            for xi, yi in zip(self.x, self.y):
                gr.polyline([xi, xi], [0, yi])

            # restore old values
            gr.setlinecolorind(lcolor)
            gr.setlinewidth(1)