Esempio n. 1
0
def make_image(data, filepath, title, labels, major_labels):
    custom_style = Style(background='#fff',
                         plot_background='transparent',
                         title_font_size=14,
                         guide_stroke_dasharray='1,0',
                         major_guide_stroke_dasharray='1,0',
                         foreground='rgba(0, 0, 0, .87)',
                         foreground_strong='rgba(0, 0, 0, .87)',
                         foreground_subtle='rgba(0, 0, 0, .87)',
                         stroke_opacity='1',
                         stroke_opacity_hover='1',
                         stroke_width=10,
                         stroke_width_hover=10,
                         opacity='1',
                         opacity_hover='1',
                         colors=('#C5D4B5BB', '#3D7930'))
    print(custom_style.to_dict())

    r = get_range(data)

    config = Config()
    config.interpolate = 'cubic'
    config.style = custom_style
    config.width = 400
    config.height = 225
    config.explicit_size = True
    config.margin_left = 0
    config.margin_right = 0
    config.margin_top = 10
    config.margin_bottom = 30
    config.show_minor_x_labels = False
    config.truncate_label = -1
    config.show_legend = False
    config.include_x_axis = True
    config.range = r
    config.show_dots = False

    chart = pygal.Line(config)
    chart.title = ("Throughput (%s, Mb/s)" % (title))
    chart.x_labels = labels
    chart.x_labels_major = major_labels
    chart.y_labels = [
        x for x in range(0, r[1] + 1, 100 if (r[1] > 550) else 50)
    ]
    chart.add(None, data, fill=True)
    chart.add(None, data)
    #with open(filepath, 'w') as output:
    #  output.write(chart.render())
    chart.render_to_png(filepath)