Ejemplo n.º 1
0
def create_graph(label_x, label_y, data_x, alldata_y, filename, title, start_date, end_date):

    # alter file name (linpng do not seems to like spaces in filenames

    filename = filename.replace(' ', '_')
    # Graph style
    theme.get_options()
    theme.use_color = True
    theme.default_font_size = 12
    theme.default_font_family = "AvantGarde-Book"
    theme.reinitialize()

    colors = [
        color.blue,
        color.red,
        color.green,
        color.magenta,
        color.cyan1,
        color.orange,
    ]

    can = canvas.init("%s"%filename)

    # Draw graph title
    newtitle = "/hL/20%s"%title
    left = WIDTH / 2  - font.text_width(newtitle)/2
    can.show(left, HEIGHT + DELTA, newtitle)

    zip(data_x)
    int_to_date = lambda x: '/a60{}' + time.strftime("%H:%M", time.localtime(x))

    xaxis = axis.X(
        format = int_to_date,
        label = "/20%s" % label_x,
        label_offset = (0, -DELTA),
        minor_tic_interval = X_MINOR_TICK_INTERVAL,
        tic_interval = X_TICK_INTERVAL
    )
    yaxis = axis.Y(
        label = "/20%s" % label_y,
        label_offset = (-DELTA, 0),
        minor_tic_interval = Y_MINOR_TICK_INTERVAL,
        tic_interval = Y_TICK_INTERVAL
    )

    ar = area.T(
        size = (WIDTH, HEIGHT),
        x_axis = xaxis,
        y_axis = yaxis,
        x_grid_style = line_style.gray70_dash3,
        x_range = (start_date, end_date),
        y_range = (0, Y_MAX),
        x_grid_interval = X_GRID_INTERVAL,
        y_grid_interval = Y_GRID_INTERVAL
    )

    i = 0
    # Draw a line for each columns
    for title, data_y in alldata_y.iteritems():
        plot = line_plot.T(
            label = title,
            data = zip(data_x,data_y),
            line_style = line_style.T(
                color = colors[i],
                width = 1
            )
        )
        ar.add_plot(plot)
        i += 1

    ar.draw()
    can.close()

    return True
Ejemplo n.º 2
0
def create_graph(label_x, label_y, data_x, alldata_y, filename, title,
                 start_date, end_date, start_y, end_y):
    """
    main func
    """
    # alter file name (linpng do not seems to like spaces in filenames

    filename = filename.replace(' ', '_')
    # Graph style
    theme.get_options()
    theme.use_color = True
    theme.default_font_size = 12
    theme.default_font_family = "AvantGarde-Book"
    theme.reinitialize()

    colors = [
        color.blue,
        color.red,
        color.green,
        color.magenta,
        color.cyan1,
        color.orange,
    ]

    can = canvas.init("%s" % filename)

    # Draw graph title
    newtitle = "/hL/20%s" % title
    left = WIDTH / 2 - font.text_width(newtitle) / 2
    can.show(left, HEIGHT + DELTA, newtitle)

    int_to_date = lambda x: '/a60{}' + time.strftime("%H:%M", time.localtime(x)
                                                     )

    xaxis = axis.X(format=int_to_date,
                   label="/20%s" % label_x,
                   label_offset=(0, -DELTA),
                   minor_tic_interval=X_MINOR_TICK_INTERVAL,
                   tic_interval=X_TICK_INTERVAL)
    yaxis = axis.Y(
        label="/20%s" % label_y,
        label_offset=(-DELTA, 0),
        minor_tic_interval=(end_y - start_y) / 20,
        tic_interval=(end_y - start_y) / 5,
    )

    ar = area.T(size=(WIDTH, HEIGHT),
                x_axis=xaxis,
                y_axis=yaxis,
                x_grid_style=line_style.gray70_dash3,
                x_range=(start_date, end_date),
                y_range=(start_y, end_y),
                x_grid_interval=X_GRID_INTERVAL,
                y_grid_interval=(end_y - start_y) / 5)

    i = 0
    # Draw a line for each columns
    for title, data_y in alldata_y.iteritems():
        plot = line_plot.T(label=title,
                           data=zip(data_x, data_y),
                           line_style=line_style.T(color=colors[i], width=1))
        ar.add_plot(plot)
        i += 1

    ar.draw()
    can.close()

    return True
def create_graph(label_x, label_y, data_x, alldata_y, filename, title, start_date, end_date, start_y, end_y):
    """
    main func
    """

    # alter file name (linpng do not seems to like spaces in filenames

    filename = filename.replace(" ", "_")
    # Graph style
    theme.get_options()
    theme.use_color = True
    theme.default_font_size = 12
    theme.default_font_family = "AvantGarde-Book"
    theme.reinitialize()

    colors = [
        color.blue,
        color.red,
        color.green,
        color.magenta,
        color.cyan1,
        color.orange,
        color.darkblue,
        color.darkred,
        color.darkgreen,
        color.darkmagenta,
        color.darkcyan,
        color.gold,
        color.lightblue1,
        color.orangered,
        color.lightgreen,
        color.pink,
        color.lightcyan,
        color.goldenrod,
        color.mistyrose,
        color.honeydew,
        color.gainsboro,
        color.yellow,
        color.peachpuff,
        color.turquoise,
        color.chartreuse1,
        color.pink,
        color.brown,
        color.blue,
        color.red,
        color.green,
        color.magenta,
        color.cyan1,
        color.orange,
        color.darkblue,
        color.darkred,
        color.darkgreen,
        color.darkmagenta,
        color.darkcyan,
        color.gold,
        color.lightblue1,
        color.orangered,
        color.lightgreen,
        color.pink,
        color.lightcyan,
        color.goldenrod,
        color.mistyrose,
        color.honeydew,
        color.gainsboro,
        color.yellow,
        color.peachpuff,
        color.turquoise,
        color.chartreuse1,
        color.pink,
        color.brown,
    ]

    can = canvas.init("%s" % filename)

    # Draw graph title
    newtitle = "/hL/20%s" % title
    left = WIDTH / 2 - font.text_width(newtitle) / 2
    can.show(left, HEIGHT + DELTA, newtitle)

    int_to_date = lambda x: "/a60{}" + time.strftime("%H:%M", time.localtime(x))

    xaxis = axis.X(
        format=int_to_date,
        label="/20%s" % label_x,
        label_offset=(0, -DELTA),
        minor_tic_interval=X_MINOR_TICK_INTERVAL,
        tic_interval=X_TICK_INTERVAL,
    )
    yaxis = axis.Y(
        label="/20%s" % label_y,
        label_offset=(-DELTA, 0),
        minor_tic_interval=(end_y - start_y) / 20,
        tic_interval=(end_y - start_y) / 5,
    )

    ar = area.T(
        size=(WIDTH, HEIGHT),
        x_axis=xaxis,
        y_axis=yaxis,
        x_grid_style=line_style.gray70_dash3,
        x_range=(start_date, end_date),
        y_range=(start_y, end_y),
        x_grid_interval=X_GRID_INTERVAL,
        y_grid_interval=(end_y - start_y) / 5,
    )

    i = 0
    # Draw a line for each columns
    for title, data_y in alldata_y.iteritems():
        plot = line_plot.T(label=title, data=zip(data_x, data_y), line_style=line_style.T(color=colors[i], width=1))
        ar.add_plot(plot)
        i += 1

    ar.draw()
    can.close()

    return True