Ejemplo n.º 1
0
def __bar_graphic__(data, legends, axis_labels, size, steps,  
                    type=StackedVerticalBarChart, multiline=False):
    
    if multiline:
        max_values = []
        min_values = [] 
        for row in data:
            max_values.append(max(row))
            min_values.append(min(row))
        max_value = max(max_values)
        min_value = min(min_values)
    else:
        max_value = max(data)
        min_value = min(data)

    step = ((max_value*1.05)-(min_value*0.95))/steps
    left_axis = range(int(min_value*0.95), int(max_value*1.05), int(step))
    left_axis[0]=''

    if type==StackedHorizontalBarChart:
        graph = StackedHorizontalBarChart(size[0], size[1], x_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        graph.set_axis_labels(Axis.LEFT, axis_labels)
    elif type==StackedVerticalBarChart:
        graph = StackedVerticalBarChart(size[0], size[1], y_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        graph.set_axis_labels(Axis.BOTTOM, axis_labels)
    elif type==GroupedHorizontalBarChart:
        graph = GroupedHorizontalBarChart(size[0], size[1], x_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        graph.set_axis_labels(Axis.LEFT, axis_labels)
        graph.set_bar_spacing(5)
    elif type==GroupedVerticalBarChart:
        graph = GroupedVerticalBarChart(size[0], size[1], y_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        graph.set_axis_labels(Axis.BOTTOM, axis_labels)
        graph.set_bar_spacing(5)
    else:
        pass #raise exception


    if multiline:
        for fila in data:
            graph.add_data(fila)
    else:
        graph.add_data(data)
    
    graph.set_colours([ 'FFBC13','22A410','E6EC23','2B2133','BD0915','3D43BD'])
    graph.set_bar_width(40)
    graph.set_legend(legends)
    graph.set_legend_position('b')
    
    
    return graph
Ejemplo n.º 2
0
def _bar_graph(data,
               legends,
               axis_labels,
               size,
               steps,
               type=StackedVerticalBarChart,
               multiline=False):

    if multiline:
        max_values = []
        min_values = []
        for row in data:
            max_values.append(max(row))
            min_values.append(min(row))
        max_value = max(max_values)
        min_value = min(min_values)
    else:
        max_value = max(data)
        min_value = min(data)

    #validando si hay datos para hacer grafico
    if max_value == 0:
        return None

    step = ((max_value * 1.05) - (min_value * 0.95)) / steps

    #validando en caso de el paso sea menor que uno y de cero en la conversion
    if step < 1:
        step = 1

    tope = int(round(max_value * 1.05))
    if tope < max_value:
        tope += 2
    else:
        tope += 1

    left_axis = range(int(round(min_value * 0.95)), tope, int(step))
    left_axis[0] = ''

    if type == StackedHorizontalBarChart:
        graph = StackedHorizontalBarChart(size[0],
                                          size[1],
                                          x_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.LEFT, axis_labels)
    elif type == StackedVerticalBarChart:
        graph = StackedVerticalBarChart(size[0],
                                        size[1],
                                        y_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.BOTTOM, axis_labels)
    elif type == GroupedHorizontalBarChart:
        graph = GroupedHorizontalBarChart(size[0],
                                          size[1],
                                          x_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.LEFT, axis_labels)
        graph.set_bar_spacing(5)
    elif type == GroupedVerticalBarChart:
        graph = GroupedVerticalBarChart(size[0],
                                        size[1],
                                        y_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.BOTTOM, axis_labels)
        graph.set_bar_spacing(5)
    else:
        pass  #raise exception

    if multiline:
        for fila in data:
            graph.add_data(fila)
    else:
        graph.add_data(data)

    graph.set_colours(
        ['FFBC13', '22A410', 'E6EC23', '2B2133', 'BD0915', '3D43BD'])
    graph.set_bar_width(44)
    graph.set_legend(legends)
    graph.set_legend_position('b')

    return graph
Ejemplo n.º 3
0
def _bar_graph(data, legends, axis_labels, size, steps,  
                    type=StackedVerticalBarChart, multiline=False):
    
    if multiline:
        max_values = []
        min_values = [] 
        for row in data:
            max_values.append(max(row))
            min_values.append(min(row))
        max_value = max(max_values)
        min_value = min(min_values)
    else:
        max_value = max(data)
        min_value = min(data)

    #validando si hay datos para hacer grafico
    if max_value==0:
        return None

    step = ((max_value*1.05)-(min_value*0.95))/steps
    
    #validando en caso de el paso sea menor que uno y de cero en la conversion
    if step<1:
        step = 1    

    tope = int(round(max_value*1.05))
    if tope < max_value:
        tope+=2
    else:
        tope+=1

    left_axis = range(int(round(min_value*0.95)), tope, int(step))
    left_axis[0]=''

    if type==StackedHorizontalBarChart:
        graph = StackedHorizontalBarChart(size[0], size[1], x_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.LEFT, axis_labels)
    elif type==StackedVerticalBarChart:
        graph = StackedVerticalBarChart(size[0], size[1], y_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.BOTTOM, axis_labels)
    elif type==GroupedHorizontalBarChart:
        graph = GroupedHorizontalBarChart(size[0], size[1], x_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.LEFT, axis_labels)
        graph.set_bar_spacing(5)
    elif type==GroupedVerticalBarChart:
        graph = GroupedVerticalBarChart(size[0], size[1], y_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        if axis_labels: 
            graph.set_axis_labels(Axis.BOTTOM, axis_labels)
        graph.set_bar_spacing(5)
    else:
        pass #raise exception


    if multiline:
        for fila in data:
            graph.add_data(fila)
    else:
        graph.add_data(data)
    
    graph.set_colours(COLORS)
    graph.set_bar_width(32)
    graph.set_legend(legends)
    graph.set_legend_position('b')
    
    
    return graph
Ejemplo n.º 4
0
def __bar_graphic__(data,
                    legends,
                    axis_labels,
                    size,
                    steps,
                    type=StackedVerticalBarChart,
                    multiline=False):

    if multiline:
        max_values = []
        min_values = []
        for row in data:
            max_values.append(max(row))
            min_values.append(min(row))
        max_value = max(max_values)
        min_value = min(min_values)
    else:
        max_value = max(data)
        min_value = min(data)

    step = ((max_value * 1.05) - (min_value * 0.95)) / steps
    left_axis = range(int(min_value * 0.95), int(max_value * 1.05), int(step))
    left_axis[0] = ''

    if type == StackedHorizontalBarChart:
        graph = StackedHorizontalBarChart(size[0],
                                          size[1],
                                          x_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        graph.set_axis_labels(Axis.LEFT, axis_labels)
    elif type == StackedVerticalBarChart:
        graph = StackedVerticalBarChart(size[0],
                                        size[1],
                                        y_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        graph.set_axis_labels(Axis.BOTTOM, axis_labels)
    elif type == GroupedHorizontalBarChart:
        graph = GroupedHorizontalBarChart(size[0],
                                          size[1],
                                          x_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        graph.set_axis_labels(Axis.LEFT, axis_labels)
        graph.set_bar_spacing(5)
    elif type == GroupedVerticalBarChart:
        graph = GroupedVerticalBarChart(size[0],
                                        size[1],
                                        y_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        graph.set_axis_labels(Axis.BOTTOM, axis_labels)
        graph.set_bar_spacing(5)
    else:
        pass  #raise exception

    if multiline:
        for fila in data:
            graph.add_data(fila)
    else:
        graph.add_data(data)

    graph.set_colours(
        ['FFBC13', '22A410', 'E6EC23', '2B2133', 'BD0915', '3D43BD'])
    graph.set_bar_width(40)
    graph.set_legend(legends)
    graph.set_legend_position('b')

    return graph