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)
def draw_line(valxy): import pygal from pygal import Config from pygal.style import Style config = Config() custom_style = Style(background='white', foreground='#000', foreground_strong='#000', foreground_subtle='#000', opacity='.9', opacity_hover='.6', plot_background='#fff', transition='100ms', label_font_size=12, major_label_font_size=12, value_font_family='Arial', font_family='Arial', major_label_font_family='Sans', colors=('#3333CC', '#3333CC', '#3333CC', '#3333CC'), guide_stroke_dasharray='2,7', major_guide_stroke_dasharray='2,7') config.margin_left = 0 config.margin_bottom = 0 config.width = 350 config.height = 350 config.x_title = "Angle, degrees" config.y_title = "Overlaps, %" config.explicit_size = True config.show_x_guides = False config.show_y_guides = True xy_chart = pygal.XY(config, show_legend=False, dots_size=3, style=custom_style) #interpolate='quadratic', #xy_chart.title = "Overlaps in oscillation range" xy_chart.add('', valxy) #xy_chart.y_labels = [int(phibg), int(phend)] # col=20 # stp=1 # for val in range(int(phibg), int(phend), stp): # xy_chart.add("", [{'value': val, 'color': 'rgb(%s, 0, 0)' % (col)}], # stroke_style={'width': 1, 'linejoin': 'round', 'linecap': 'round', 'linejoin': 'round'}) # col=col+stp return xy_chart.render(is_unicode=True)