Пример #1
0
def column_chart(self, label=0, value=1, path=None, width=None, height=None):
    """
    Render a lattice/grid of column charts using :class:`leather.Lattice`.

    :param label:
        The name or index of a column to plot as the labels of the chart.
        Defaults to the first column in the table.
    :param value:
        The name or index of a column to plot as the values of the chart.
        Defaults to the second column in the table.
    :param path:
        If specified, the resulting SVG will be saved to this location. If
        :code:`None` and running in IPython, then the SVG will be rendered
        inline. Otherwise, the SVG data will be returned as a string.
    :param width:
        The width of the output SVG.
    :param height:
        The height of the output SVG.
    """
    if type(label) is int:
        label_name = self.column_names[label]
    else:
        label_name = label

    if type(value) is int:
        value_name = self.column_names[value]
    else:
        value_name = value

    chart = leather.Lattice(shape=leather.Columns())
    chart.add_x_axis(name=label_name)
    chart.add_y_axis(name=value_name)
    chart.add_many(self.values(), x=label, y=value, titles=self.keys())

    return chart.to_svg(path=path, width=width, height=height)
Пример #2
0
def line_chart(self, x=0, y=1, path=None, width=None, height=None):
    """
    Render a lattice/grid of line charts using :class:`leather.Lattice`.

    :param x:
        The name or index of a column to plot as the x axis of the chart.
        Defaults to the first column in the table.
    :param y:
        The name or index of a column to plot as the y axis of the chart.
        Defaults to the second column in the table.
    :param path:
        If specified, the resulting SVG will be saved to this location. If
        :code:`None` and running in IPython, then the SVG will be rendered
        inline. Otherwise, the SVG data will be returned as a string.
    :param width:
        The width of the output SVG.
    :param height:
        The height of the output SVG.
    """
    if type(x) is int:
        x_name = self.column_names[x]
    else:
        x_name = x

    if type(y) is int:
        y_name = self.column_names[y]
    else:
        y_name = y

    chart = leather.Lattice(shape=leather.Line())
    chart.add_x_axis(name=x_name)
    chart.add_y_axis(name=y_name)
    chart.add_many(self.values(), x=x, y=y, titles=self.keys())

    return chart.to_svg(path=path, width=width, height=height)
Пример #3
0
    def test_add_many(self):
        lattice = leather.Lattice()
        lattice.add_many([self.data1, self.data2, self.data1])

        svg = self.render_chart(lattice)

        self.assertElementCount(svg, '.axis', 6)
        self.assertElementCount(svg, '.series', 3)
        self.assertElementCount(svg, '.lines', 3)
Пример #4
0
    def test_add_one(self):
        lattice = leather.Lattice()
        lattice.add_one(self.data1)
        lattice.add_one(self.data2)

        svg = self.render_chart(lattice)

        self.assertElementCount(svg, '.axis', 4)
        self.assertElementCount(svg, '.series', 2)
        self.assertElementCount(svg, '.lines', 2)
def plotCyberH(file, genereted_chart_file):
    roll1, mcf1, ifd1, a1, mcf2, ifp2, ifd2, a2, mcf3, ifp3, ifd3, a3, mcf4, ifp4, ifd4, a4, mcf5, ifp5, ifd5, a5, roll5, c, c_ano, usado = [],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]
    line_num = 0

    for line in file:
        if (line_num > 1):
            line_array = line.split(' ')
            roll1.append((line_num, float(line_array[1])))
            roll5.append((line_num, float(line_array[21])))
            c.append((line_num, float(line_array[22])))
            c_ano.append((line_num, float(line_array[23])))
            usado.append((line_num, float(line_array[24])))

            mcf1.append((line_num, float(line_array[2])))
            ifd1.append((line_num, float(line_array[3])))
            a1.append((line_num, float(line_array[4])))

            mcf2.append((line_num, float(line_array[5])))
            ifp2.append((line_num, float(line_array[6])))
            ifd2.append((line_num, float(line_array[7])))
            a2.append((line_num, float(line_array[8])))

            mcf3.append((line_num, float(line_array[9])))
            ifp3.append((line_num, float(line_array[10])))
            ifd3.append((line_num, float(line_array[11])))
            a3.append((line_num, float(line_array[12])))

            mcf4.append((line_num, float(line_array[13])))
            ifp4.append((line_num, float(line_array[14])))
            ifd4.append((line_num, float(line_array[15])))
            a4.append((line_num, float(line_array[16])))

            mcf5.append((line_num, float(line_array[17])))
            ifp5.append((line_num, float(line_array[18])))
            ifd5.append((line_num, float(line_array[19])))
            a5.append((line_num, float(line_array[20])))
        line_num += 1

    lattice = leather.Lattice(leather.Line(stroke_color=None, width=0.5))
    lattice.add_many([
        roll1, mcf1, ifd1, a1, mcf2, ifp2, ifd2, a2, mcf3, ifp3, ifd3, a3,
        mcf4, ifp4, ifd4, a4, mcf5, ifp5, ifd5, a5, roll5, c, c_ano, usado
    ],
                     titles=[
                         'roll1', 'mcf1', 'ifd1', 'a1', 'mcf2', 'ifp2', 'ifd2',
                         'a2', 'mcf3', 'ifp3', 'ifd3', 'a3', 'mcf4', 'ifp4',
                         'ifd4', 'a4', 'mcf5', 'ifp5', 'ifd5', 'a5', 'roll5',
                         'c', 'c_ano', 'usado'
                     ])
    lattice.add_x_scale(0, line_num - 30)
    lattice.add_y_scale(0, 250),
    lattice.to_svg(genereted_chart_file, 1700, 950)
    webbrowser.open('file://' + os.path.realpath(genereted_chart_file))
    def test_bars_different(self):
        data1 = [(3, 'foo'), (5, 'bar'), (9, 'bing')]

        data2 = [(3, 'foo'), (5, 'bar'), (9, 'baz')]

        lattice = leather.Lattice(shape=leather.Bars())
        lattice.add_many([data1, data2])

        svg = self.render_chart(lattice)

        self.assertElementCount(svg, '.axis', 4)
        self.assertElementCount(svg, '.series', 2)
        self.assertElementCount(svg, '.bars', 2)
def plotIMU(file, genereted_chart_file):
    w, x, y, z = [], [], [], []
    line_num = 0

    for line in file:
        if (line_num > 1):
            line_array = line.split('\t')
            w.append((line_num, float(line_array[1])))
            x.append((line_num, float(line_array[2])))
            y.append((line_num, float(line_array[3])))
            z.append((line_num, float(line_array[4])))

        line_num += 1

    lattice = leather.Lattice(leather.Line(stroke_color=None, width=2))
    lattice.add_many([w, x, y, z], titles=['w', 'x', 'y', 'z'])
    lattice.to_svg(genereted_chart_file, 1700, 950)
    webbrowser.open('file://' + os.path.realpath(genereted_chart_file))
Пример #8
0
import leather

data1 = [(0, 3), (4, 5), (7, 9), (8, 4)]

data2 = [(3, 4), (3, 4), (5, 6), (7, 10), (8, 2)]

data3 = [(2, 4), (3, 5), (6, 2), (8, 3), (10, 5)]

lattice = leather.Lattice()
lattice.add_y_scale(-20, 20)
lattice.add_x_axis(ticks=10)
lattice.add_many([data1, data2, data3], titles=['First', 'Second', 'Third'])
lattice.to_svg('test.svg')
def plotVMG30(file, genereted_chart_file):
    f11,f12,f21,f22,f31,f32,f41,f42,f51,f52,abd1,abd2,abd3,abd4,pa,tco,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,hroll,hpitch,hyaw,wroll,wpitch,wyaw = [],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]
    line_num = 0

    for line in file:
        if (line_num > 1):
            line_array = line.split('\t')

            f11.append((line_num, float(line_array[1])))
            f12.append((line_num, float(line_array[2])))
            f21.append((line_num, float(line_array[3])))
            f22.append((line_num, float(line_array[4])))

            f31.append((line_num, float(line_array[5])))
            f32.append((line_num, float(line_array[6])))
            f41.append((line_num, float(line_array[7])))
            f42.append((line_num, float(line_array[8])))

            f51.append((line_num, float(line_array[9])))
            f52.append((line_num, float(line_array[10])))
            pa.append((line_num, float(line_array[15])))
            tco.append((line_num, float(line_array[16])))

            abd1.append((line_num, float(line_array[11])))
            abd2.append((line_num, float(line_array[12])))
            abd3.append((line_num, float(line_array[13])))
            abd4.append((line_num, float(line_array[14])))

            p1.append((line_num, float(line_array[17])))
            p2.append((line_num, float(line_array[18])))
            p3.append((line_num, float(line_array[19])))
            p4.append((line_num, float(line_array[20])))
            p5.append((line_num, float(line_array[21])))

            p6.append((line_num, float(line_array[22])))
            p7.append((line_num, float(line_array[23])))
            p8.append((line_num, float(line_array[24])))
            p9.append((line_num, float(line_array[25])))
            p10.append((line_num, float(line_array[26])))

            hroll.append((line_num, float(line_array[27])))
            hpitch.append((line_num, float(line_array[28])))
            hyaw.append((line_num, float(line_array[29])))

            wroll.append((line_num, float(line_array[30])))
            wpitch.append((line_num, float(line_array[31])))
            wyaw.append((line_num, float(line_array[32])))
        line_num += 1

    lattice = leather.Lattice(leather.Line(stroke_color=None, width=0.5))
    lattice.add_many([
        f11, f12, f21, f22, f31, f32, f41, f42, f51, f52, abd1, abd2, abd3,
        abd4, pa, tco, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, hroll, hpitch,
        hyaw, wroll, wpitch, wyaw
    ],
                     titles=[
                         'f11', 'f12', 'f21', 'f22', 'f31', 'f32', 'f41',
                         'f42', 'f51', 'f52', 'abd1', 'abd2', 'abd3', 'abd4',
                         'pa', 'tco', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7',
                         'p8', 'p9', 'p10', 'hroll', 'hpitch', 'hyaw', 'wroll',
                         'wpitch', 'wyaw'
                     ])
    lattice.to_svg(genereted_chart_file, 1700, 950)
    webbrowser.open('file://' + os.path.realpath(genereted_chart_file))