Beispiel #1
0
 def getHTML(self):
     if not self.enabled:
         return ''
     if not self.data or not self.curves:
         return '<span>No data or curves found</span>'
     with self.lock:
         for i, (d, c) in enumerate(zip(self.data, self.curves)):
             try:
                 # add a point "current value" at "right now" to avoid curves
                 # not updating if the value doesn't change
                 now = currenttime()
                 if d[0][-1] < now - 10:
                     self.updatevalues(i, now, d[1][-1])
                 c.x, c.y = self.maybeDownsamplePlotdata(d)
             except IndexError:
                 # no data (yet)
                 pass
     c = self.axes.getCurves()
     self.axes.setWindow(c.xmin, c.xmax, c.ymin, c.ymax)
     if os.path.isfile(self.tempfile):
         os.unlink(self.tempfile)
     gr.beginprint(self.tempfile)
     gr.setwsviewport(0, self.width * 0.0022, 0, self.height * 0.0022)
     try:
         self.plot.drawGR()
     except Exception as err:
         return html.escape('Error generating plot: %s' % err)
     finally:
         gr.endprint()
         gr.clearws()
     with open(self.tempfile, 'rb') as fp:
         imgbytes = fp.read()
     return ('<img src="data:image/svg+xml;base64,%s" '
             'style="width: %sex; height: %sex">' %
             (b64encode(imgbytes).decode(), self.width, self.height))
Beispiel #2
0
 def save(self, path):
     (p, ext) = os.path.splitext(path)
     if ext.lower()[1:] == gr.GRAPHIC_GRX:
         gr.begingraphics(path)
         self.draw()
         gr.endgraphics()
     else:
         gr.beginprint(path)
         self.draw()
         gr.endprint()
     self.repaint()
Beispiel #3
0
 def save(self, path):
     (p, ext) = os.path.splitext(path)
     if ext.lower()[1:] == gr.GRAPHIC_GRX:
         gr.begingraphics(path)
         self.draw()
         gr.endgraphics()
     else:
         gr.beginprint(path)
         self.draw()
         gr.endprint()
     self.repaint()
Beispiel #4
0
    def export_image(self):
        extensions = (".pdf", ".png", ".bmp", ".jpg", ".jpeg", ".png",
                      ".tiff", ".fig", ".svg", ".wmf", ".eps", ".ps")
        qtext = "*" + " *".join(extensions)
        filepath = QtWidgets.QFileDialog.getSaveFileName(self, "Save Image",
                                                           ".", "Image Files ({})".format(qtext))[0]
        if not filepath:
            return

        if filepath.endswith('.eps') or filepath.endswith('.ps'):
            gr.beginprintext(filepath, 'Color', 'A4', 'Landscape')
            self.draw(now=True, wsviewport=(0, 0.297*0.9, 0, 0.21*0.95))
        else:
            gr.beginprint(filepath)
            self.draw(now=True)
        gr.endprint()
Beispiel #5
0
    def export_image(self):
        extensions = (".pdf", ".png", ".bmp", ".jpg", ".jpeg", ".png", ".tiff",
                      ".fig", ".svg", ".wmf", ".eps", ".ps")
        qtext = "*" + " *".join(extensions)
        filepath = QtWidgets.QFileDialog.getSaveFileName(
            self, "Save Image", ".", "Image Files ({})".format(qtext))[0]
        if len(filepath) == 0:
            return

        if filepath.endswith('.eps') or filepath.endswith('.ps'):
            gr.beginprintext(filepath, 'Color', 'A4', 'Landscape')
            self.draw(now=True, wsviewport=(0, 0.297 * 0.9, 0, 0.21 * 0.95))
        else:
            gr.beginprint(filepath)
            self.draw(now=True)
        gr.endprint()
def draw(
    x,
    x_extents=(-100, 100),
    y_extents=(-100, 100),
    landmarks=None,
    observations=None,
    particles=None,
    weights=None,
    ellipses=None,
    fig=None,
):
    """Draw vehicle state x = [x, y, theta] on the map."""
    xmin, xmax = x_extents
    ymin, ymax = y_extents
    tick_spacing = (xmax - xmin) / 20

    if fig is not None:
        print("saving", draw.i)
        gr.beginprint("{}_{:03d}.pdf".format(fig, draw.i))

    init_plot_window(xmin, xmax, ymin, ymax)
    draw_vehicle(x)

    if landmarks is not None:
        draw_landmarks(landmarks)

    if observations is not None:
        draw_observation_lines(x, observations)

    if particles is not None:
        draw_particles(particles, weights=weights)

    if ellipses is not None:
        for i, ell in enumerate(ellipses):
            draw_ellipse(ell, alpha=(0.1))

    draw_axes(tick_spacing, xmin, ymin)

    gr.updatews()
    if fig is not None:
        gr.endprint()
    draw.i += 1
    return
def draw(x,
         x_extents=(-100, 100),
         y_extents=(-100, 100),
         landmarks=None,
         observations=None,
         particles=None,
         weights=None,
         fig=None):
    """Draw vehicle state x = [x, y, theta] on the map."""
    xmin, xmax = x_extents
    ymin, ymax = y_extents
    tick_spacing = (xmax - xmin) / 20

    if fig is not None:
        print('saving', draw.i)
        gr.beginprint('{}_{}.pdf'.format(fig, draw.i))

    init_plot_window(xmin, xmax, ymin, ymax)
    draw_vehicle(x)
    # draw_vehicle_ellipse(x, np.eye(3))  # this works; not needed yet

    if landmarks is not None:
        draw_landmarks(landmarks)

    if observations is not None:
        draw_observation_lines(x, observations)

    if particles is not None:
        draw_particles(particles, weights=weights)

    draw_axes(tick_spacing, xmin, ymin)

    gr.updatews()
    if fig is not None:
        gr.endprint()
    draw.i += 1
    return
Beispiel #8
0
Datei: mlab.py Projekt: j-fu/gr
def savefig(filename):
    gr.beginprint(filename)
    _plot_data()
    gr.endprint()
Beispiel #9
0
def savefig(filename):
    gr.beginprint(filename)
    _plot_data()
    gr.endprint()
from __future__ import print_function
from __future__ import unicode_literals

import sys
import os
import numpy as np
import gr

sys.path.insert(0, os.path.abspath('../src'))
from statistics.rdf import Kernels

x = np.linspace(-1.25, 1.25, 500)
for name in dir(Kernels):
    if name.startswith('_') or name == 'bandwidth':
        continue
    kernel = getattr(Kernels, name)
    y = kernel(x)
    gr.beginprint(name.lower()+'.svg')
    gr.clearws()
    gr.setwsviewport(0, 0.1, 0, 0.06)
    gr.setviewport(0, 1, 0, 1)
    gr.setwindow(-1.25, 1.25, -0.25, 1.25)
    gr.grid(0.1, 0.1, 0, 0, 5, 5)
    gr.axes(0.1, 0.1, 0, 0, 5, 5, -0.01)
    gr.setlinewidth(2)
    gr.setlinecolorind(2)
    gr.polyline(x, y)
    gr.setlinecolorind(1)
    gr.setlinewidth(1)
    gr.updatews()
    gr.endprint()
import gr
from gr.pygr import plot
from math import pi
import numpy as np

L = 5.0
x = np.linspace(0, L, 100)
y1 = np.sin(2 * pi * x / L)
y2 = np.cos(2 * pi * x / L)

gr.beginprint("TEMP_08.pdf")
plt = plot(x, y1, x, y2)
gr.endprint()