def index(request): custom_style = Style(background='transparent', plot_background='transparent', legend_font_size=30) config = Config() config.fill = True pie_chart = pygal.Pie(legend_at_bottom=True, inner_radius=.6, style=custom_style, margin=0, width=400) #pie_chart.title = 'Graduation Rate' pie_chart.add('Graduated', grad_rate) pie_chart.add('Ejected', eject_rate) pie_chart.render_to_file('webapp/static/graduation_donut.svg') pending_applications = Client.objects.filter( client_phase='Applicant').count() sum_residents = Client.objects.filter(client_phase='Resident').count() applicants = Client.objects.filter( client_phase='Applicant').order_by('-id')[:6] sum_applicants = Client.objects.filter( client_phase='Applicant').count() - 6 return render( request, 'index.html', { 'pending_applications': pending_applications, 'applicants': applicants, 'sum_applicants': sum_applicants, 'sum_residents': sum_residents })
def test_gradient_for(chart): config = Config() config.style = styles['dark'] config.defs.append(''' <linearGradient id="gradient-0" x1="0" x2="0" y1="0" y2="1"> <stop offset="0%" stop-color="#ff5995" /> <stop offset="100%" stop-color="#feed6c" /> </linearGradient> ''') config.defs.append(''' <linearGradient id="gradient-1" x1="0" x2="0" y1="0" y2="1"> <stop offset="0%" stop-color="#b6e354" /> <stop offset="100%" stop-color="#8cedff" /> </linearGradient> ''') config.css.append('''inline: .color-0 { fill: url(#gradient-0) !important; stroke: url(#gradient-0) !important; }''') config.css.append('''inline: .color-1 { fill: url(#gradient-1) !important; stroke: url(#gradient-1) !important; }''') chart = CHARTS_BY_NAME[chart](config) chart.add('1', [1, 3, 12, 3, 4, None, 9]) chart.add('2', [7, -4, 10, None, 8, 3, 1]) chart.x_labels = ('a', 'b', 'c', 'd', 'e', 'f', 'g') chart.legend_at_bottom = True chart.interpolate = 'cubic' return chart.render_response()
def test_config_behaviours(): line1 = Line() line1.show_legend = False line1.fill = True line1.pretty_print = True line1.x_labels = ['a', 'b', 'c'] line1.add('_', [1, 2, 3]) l1 = line1.render() q = line1.render_pyquery() assert len(q(".axis.x")) == 1 assert len(q(".axis.y")) == 1 assert len(q(".plot .series path")) == 1 assert len(q(".legend")) == 0 assert len(q(".x.axis .guides")) == 3 assert len(q(".y.axis .guides")) == 21 assert len(q(".dots")) == 3 assert q(".axis.x text").map(texts) == ['a', 'b', 'c'] line2 = Line( show_legend=False, fill=True, pretty_print=True, x_labels=['a', 'b', 'c']) line2.add('_', [1, 2, 3]) l2 = line2.render() assert l1 == l2 class LineConfig(Config): show_legend = False fill = True pretty_print = True x_labels = ['a', 'b', 'c'] line3 = Line(LineConfig) line3.add('_', [1, 2, 3]) l3 = line3.render() assert l1 == l3 line4 = Line(LineConfig()) line4.add('_', [1, 2, 3]) l4 = line4.render() assert l1 == l4 line_config = Config() line_config.show_legend = False line_config.fill = True line_config.pretty_print = True line_config.x_labels = ['a', 'b', 'c'] line5 = Line(line_config) line5.add('_', [1, 2, 3]) l5 = line5.render() assert l1 == l5
def renderGraph(self,graphingParams): config = Config() config.legend_at_bottom = True config.legend_at_bottom_columns = 2 config.margin_bottom = 30 aStyle = DefaultStyle(font_family='Arial',colors=self.getColors(),background='rgba(255,255,255,1)') pie_chart = pygal.Pie(config,style=aStyle) pie_chart.title = graphingParams.get('title','') for each in graphingParams.get('items',[]): descr = each.get('descr','') value = each.get('value',0.0) pie_chart.add(descr,value) return pie_chart.render()
def drawPercentile(percentile, x_label, path, showPlot): config = Config() config.show_legend = False # config.range = (0,1) dark_lighten_style = LightenStyle('#336676', base_style=LightColorizedStyle) dark_lighten_style.background = '#ffffff' dark_lighten_style.opacity = 1 dark_lighten_style.font_family = "DejaVu Sans" dark_lighten_style.legend_font_family = "DejaVu Sans" dark_lighten_style.major_label_font_family = "DejaVu Sans" dark_lighten_style.title_font_family = "DejaVu Sans" dark_lighten_style.tooltip_font_family = "DejaVu Sans" dark_lighten_style.label_font_family = "DejaVu Sans" dark_lighten_style.label_font_size = 40 dark_lighten_style.major_label_font_size = 40 # print(dark_lighten_style.to_dict()) bar_chart = pygal.Bar(config, width=1600, height=1000, rounded_bars=6, style=dark_lighten_style, margin=0) bar_chart.x_labels = x_label #['Concentration', 'Stability', 'Focus Continuity'] #map(str, range(2002, 2013)) bar_chart.y_labels = (0, 0.2, 0.4, 0.6, 0.8, 1) # bar_chart.add('Percentile0', rd1.percentile[0]) # bar_chart.add('Percentile1', rd1.percentile[1]) # bar_chart.add('Percentile2', rd1.percentile[2]) bar_chart.add('Percentile', [{ 'value': 1 - percentile[0], 'color': selectColor(percentile[0]) }, { 'value': 1 - percentile[1], 'color': selectColor(percentile[1]) }, { 'value': 1 - percentile[2], 'color': selectColor(percentile[2]) }]) if showPlot: display({'image/svg+xml': bar_chart.render()}, raw=True, dpi=200) bar_chart.render_to_png(path + 'Percentile.png', fill=True, dpi=200)
def genweightchart(): '''Generate weight chart with Pygal''' weighthistory = session.query(Weight) \ .filter_by(user_id=current_user.id) \ .order_by(Weight.id.desc()) \ .all() maxweight = session.query(Weight) \ .filter_by(user_id=current_user.id) \ .order_by(Weight.id.desc()) \ .first() if maxweight is None: maxrange = 100 else: maxrange = (int(maxweight.weight) + 50) custom_style = Style( background='transparent', value_font_size=24, title_font_size=36, margin=1, plot_background='transparent', foreground='#53E89B', foreground_strong='#53A0E8', foreground_subtle='#630C0D', opacity='.6', opacity_hover='.9', transition='400ms ease-in', colors=('#5cb85c', '#f0ad4e', '#d9534f')) config = Config() config.show_legend = True config.legend_at_bottom=True config.y_labels = range(0, maxrange, 25) config.human_readable = True config.fill = True config.style=custom_style config.print_labels=True config.no_data_text='Add weight measurements!' wlist = [] for entry in enumerate(weighthistory): wlist.append(entry[1].weight) line_chart = pygal.Line(config) line_chart.title = "Weight History" line_chart.add('Values', wlist) chart = line_chart.render(is_unicode=True) return chart
def define_config(): """Defines some configuration options for the pygal plot.""" config = Config() config.show_legend = False config.legend_at_bottom = True config.human_readable = True config.print_values = True config.show_x_labels = True config.show_y_labels = True config.fill = True return config
def node_apply_end(repo, node, duration=None, interactive=None, result=None, **kwargs): if environ.get('TERM_PROGRAM', None) != "iTerm.app" or not interactive: LOG.debug("skipping iTerm stats (wrong terminal)") return if not IMPORTS: LOG.error("failed to import dependencies of itermstats plugin") return css_file = NamedTemporaryFile(delete=False) css_file.write(".text-overlay { display: none; }") css_file.close() config = Config( height=150, style=STYLE, width=350, ) config.css.append(css_file.name) chart = Pie(config) chart.add('correct', result.correct) chart.add('fixed', result.fixed) chart.add('skipped', result.skipped) chart.add('failed', result.failed) png_data = cairosvg.svg2png(bytestring=chart.render()) png_data_b64 = b64encode(png_data) remove(css_file.name) print("\033]1337;File=inline=1:{}\007".format(png_data_b64))
def renderJobActionAveragesGraph(self,jobActionAverages): if jobActionAverages: params = self.getGraphParams(jobActionAverages) aStyle = DefaultStyle(font_family='Arial',colors=self.getColors(),background='rgba(255,255,255,1)') config = Config() config.y_title = 'Days to Completion' config.x_title = 'Year' config.human_readable = True bar_chart2 = pygal.Bar(config,style=aStyle) bar_chart2.title = 'Time to Completion' bar_chart2.x_labels = map(str,params.get('dateRange',())) for item in params.get('items',[]): bar_chart2.add(item.get('title',''), item.get('days',[0])) return bar_chart2.render() return ''
def test_custom_css_file(): from tempfile import NamedTemporaryFile custom_css = ''' {{ id }}text { fill: green; font-family: monospace; } {{ id }}.legends .legend text { font-size: {{ font_sizes.legend }}; } {{ id }}.axis { stroke: #666; } {{ id }}.axis text { font-size: {{ font_sizes.label }}; font-family: sans; stroke: none; } {{ id }}.axis.y text { text-anchor: end; } {{ id }}#tooltip text { font-size: {{ font_sizes.tooltip }}; } {{ id }}.dot { fill: yellow; } {{ id }}.color-0 { stroke: #ff1100; fill: #ff1100; } {{ id }}.color-1 { stroke: #ffee00; fill: #ffee00; } {{ id }}.color-2 { stroke: #66bb44; fill: #66bb44; } {{ id }}.color-3 { stroke: #88bbdd; fill: #88bbdd; } {{ id }}.color-4 { stroke: #0000ff; fill: #0000ff; } ''' custom_css_file = '/tmp/pygal_custom_style.css' with open(custom_css_file, 'w') as f: f.write(custom_css) config = Config(fill=True, interpolate='cubic') config.css.append(custom_css_file) chart = StackedLine(config) chart.add('A', [1, 3, 5, 16, 13, 3, 7]) chart.add('B', [5, 2, 3, 2, 5, 7, 17]) chart.add('C', [6, 10, 9, 7, 3, 1, 0]) chart.add('D', [2, 3, 5, 9, 12, 9, 5]) chart.add('E', [7, 4, 2, 1, 2, 10, 0]) return chart.render_response()
def genweightchart(): '''Generate weight chart with Pygal''' weighthistory = session.query(Weight) \ .filter_by(user_id=current_user.id) \ .order_by(Weight.id.asc()) \ .all() maxweight = session.query(Weight) \ .filter_by(user_id=current_user.id) \ .order_by(Weight.weight.desc()) \ .first() if maxweight is None: maxrange = 100 else: maxrange = (int(maxweight.weight) + 5) custom_style = Style( background='transparent', value_font_size=24, title_font_size=36, label_font_size=24, margin=5, plot_background='transparent', foreground='#53E89B', foreground_strong='#53A0E8', foreground_subtle='#630C0D', opacity='.6', opacity_hover='.9', transition='400ms ease-in', colors=('#5cb85c', '#f0ad4e', '#d9534f')) config = Config() config.show_legend = False config.y_labels = range(0, maxrange, 5) config.margin_bottom=50 config.human_readable = True config.fill = True config.style=custom_style config.print_labels=True config.no_data_text='Add weight measurements!' wlist = [] for entry in enumerate(weighthistory): wlist.append(entry[1].weight) line_chart = pygal.Line(config) line_chart.title = "Weight History" line_chart.add('Values', wlist) chart = line_chart.render(is_unicode=True) return chart
def test_inline_css(Chart): css = "{{ id }}text { fill: #bedead; }\n" config = Config() config.css.append('inline:' + css) chart = Chart(config) chart.add('/', [10, 1, 5]) svg = chart.render().decode('utf-8') assert '#bedead' in svg
def test_config_behaviours(): """Test that all different way to set config produce same results""" line1 = Line() line1.show_legend = False line1.fill = True line1.pretty_print = True line1.no_prefix = True line1.x_labels = ['a', 'b', 'c'] line1.add('_', [1, 2, 3]) l1 = line1.render() q = line1.render_pyquery() assert len(q(".axis.x")) == 1 assert len(q(".axis.y")) == 1 assert len(q(".plot .series path")) == 1 assert len(q(".legend")) == 0 assert len(q(".x.axis .guides")) == 3 assert len(q(".y.axis .guides")) == 11 assert len(q(".dots")) == 3 assert q(".axis.x text").map(texts) == ['a', 'b', 'c'] line2 = Line( show_legend=False, fill=True, pretty_print=True, no_prefix=True, x_labels=['a', 'b', 'c']) line2.add('_', [1, 2, 3]) l2 = line2.render() assert l1 == l2 class LineConfig(Config): show_legend = False fill = True pretty_print = True no_prefix = True x_labels = ['a', 'b', 'c'] line3 = Line(LineConfig) line3.add('_', [1, 2, 3]) l3 = line3.render() assert l1 == l3 line4 = Line(LineConfig()) line4.add('_', [1, 2, 3]) l4 = line4.render() assert l1 == l4 line_config = Config() line_config.show_legend = False line_config.fill = True line_config.pretty_print = True line_config.no_prefix = True line_config.x_labels = ['a', 'b', 'c'] line5 = Line(line_config) line5.add('_', [1, 2, 3]) l5 = line5.render() assert l1 == l5
def visualization(self, img, prediction): """Plot list of predictions on barchart Args: img (np.array): image as array prediction (list): array of emotions probabilities Returns: list: barchart as array """ config = Config() config.show_legend = False config.print_labels = True config.show_y_labels = False config.show_y_guides = False config.show_x_guides = False config.max_scale = 12 config.width = img.width config.height = img.height custom_style = Style(background='transparent', plot_background='transparent', foreground='transparent', colors=('#19d5ff', '#19d5ff', '#19d5ff', '#19d5ff', '#19d5ff'), opacity='.8', value_label_font_size=img.width // 30, value__label_font_family='monospace') labels = ['Angry', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral'] data = list(zip(prediction, labels)) data_dict = [] for val, label in data: data_dict.append({'value': val, 'label': label}) bar_chart = pygal.HorizontalBar(config=config, style=custom_style) bar_chart.add('', data_dict) imgByteArr = BytesIO() bar_chart.render_to_png(imgByteArr) #pygal, no comments #bar = Image.open('./tmp.png') bar = Image.open(imgByteArr) return bar
def test_gradient_for(chart): config = Config() config.style = styles["dark"] config.defs.append( """ <linearGradient id="gradient-0" x1="0" x2="0" y1="0" y2="1"> <stop offset="0%" stop-color="#ff5995" /> <stop offset="100%" stop-color="#feed6c" /> </linearGradient> """ ) config.defs.append( """ <linearGradient id="gradient-1" x1="0" x2="0" y1="0" y2="1"> <stop offset="0%" stop-color="#b6e354" /> <stop offset="100%" stop-color="#8cedff" /> </linearGradient> """ ) config.css.append( """inline: .color-0 { fill: url(#gradient-0) !important; stroke: url(#gradient-0) !important; }""" ) config.css.append( """inline: .color-1 { fill: url(#gradient-1) !important; stroke: url(#gradient-1) !important; }""" ) chart = CHARTS_BY_NAME[chart](config) chart.add("1", [1, 3, 12, 3, 4, None, 9]) chart.add("2", [7, -4, 10, None, 8, 3, 1]) chart.x_labels = ("a", "b", "c", "d", "e", "f", "g") chart.legend_at_bottom = True chart.interpolate = "cubic" return chart.render_response()
def charts(): try: dateline = pygal.Line() config = Config() config.box_mode = True dateline = pygal.Line(config) dateline.title = 'Remaining Stories/Bugs' dateline.x_labels = ['21 May 2018','28 May 2018','4 June 2018','11 June 2018','18 June 2018','25 June 2018','2 July 2018','9 July 2018','16 July 2018','23 July 2018','30 July 2018','6 August 2018','13 August 2018','20 August 2018','27 August 2018','3 September 2018','10 September 2018'] dateline.add('Glacier', [None, None, None, None, None, 0, 7, 1, 1, 16, 17, 15, 16, 14, 15, 16]) dateline.add('APS', [None, None, None, None, None, None, None, 0, 60, 128, 128, 117, 120, 121, 116, 118]) dateline.add('AWS Migration', [9, 9, 9, 7, 9, 13, 9, 27, 81, 97, 96, 93, 85, 94, 86, 90, 79]) dateline.add('DBP Builder App', [None, None, None, None, None, None, None, 0, 4, 14, 16, 16, 26, 41, 46, 46, 30]) dateline.add('Workspace', [None, None, None, None, None, None, None, None, 0, 69, 62, 62, 61, 61, 55, 60, 64]) graph_data = dateline.render_data_uri() return render_template("dateline.html",graph_data=graph_data) except Exception as e: return (str(e))
def test_css(Chart): css = "{{ id }}text { fill: #bedead; }\n" with NamedTemporaryFile('w') as f: f.write(css) f.flush() config = Config() config.css.append(f.name) chart = Chart(config) chart.add('/', [10, 1, 5]) svg = chart.render().decode('utf-8') assert '#bedead' in svg
def test_css(Chart): css = "{{ id }}text { fill: #bedead; }\n" css_file = '/tmp/pygal_custom_style-%s.css' % uuid4() with open(css_file, 'w') as f: f.write(css) config = Config() config.css.append(css_file) chart = Chart(config) chart.add('/', [10, 1, 5]) svg = chart.render().decode('utf-8') assert '#bedead' in svg
def get_price_chart(self, stat): config = Config() config.show_legend = False config.human_readable = True config.x_label_rotation = 90 config.pretty_print = True config.min_scale = 12 config.height = 480 price_chart = pygal.Line(config) price_chart.title = '售价走势图' price_chart.x_labels = map( lambda x: x.date_created.strftime("%Y-%m-%d"), stat) price_chart.add('价格', [row.price for row in stat]) return price_chart.render_data_uri()
def init_bar_graph(): config = Config() config.x_label_rotation = 45 config.show_legend = True config.title = 'Most-Starred Top-5 Programming Languages\'s Projects on Github' config.y_title = 'Stars' chart = Bar(config) return chart
def __init__(self, path='/tmp/graph.png', locale={}, extra_css=[]): self.style = None self.chart = None self.path = path self.locale = locale self.config = Config() self.config.no_data_text = 'No result found' self.config.no_data_font_size = 13 self.config.x_label_rotation = 45 self.config.truncate_legend = 255 self.config.truncate_label = 255 for css in extra_css: self.config.css.append(css) if 'STR_NODATA' in self.locale: self.config.no_data_text = self.locale['STR_NODATA']
def make_chart_pygal(model_name, chart_id, options): points = make_points(model_name, chart_id) ''' options ''' if options.get('color') == options.get('bg_color'): color_to_contrast = options.get('color', '#292928') options['bg_color'], options['color'] = get_contrasted_colors( color_to_contrast) scatter_plot = options.get('flag_scatter_plot', False) show_grid = options.get('flag_show_grid', True) logscale_y = options.get('flag_logscale_y', False) pygal_config = PygalConfig() pygal_config.show_dots = False pygal_config.style = PygalStyle(colors=(options.get('color', 'black'), ), plot_background=options.get( 'bg_color', '#cccccc')) stroke_options = dict() if scatter_plot: pygal_config.stroke = True stroke_options['dasharray'] = '10, 20' if logscale_y: pygal_config.logarithmic = True stroke_options['width'] = options.get('line_width', 2) pygal_config.stroke_style = stroke_options pygal_config.title = options.get('title', 'Pygal') pygal_config.show_x_guides = show_grid pygal_config.show_y_guides = show_grid chart = pygal.XY(pygal_config, width=600, height=600) chart.add(options.get('y_label', 'y'), points) return chart
def languages_draw(prefix, file_name, dir_name, time_title, names, counts): chart = pygal.Bar(interpolate='cubic', width=1000) config = Config() config.show_legend = False config.human_readable = True config.fill = True config.style = DarkColorizedStyle config.label_font_size = 36 config.x_label_rotation = 45 chart.config = config chart.title = file_name + " [" + time_title + "]" chart.x_labels = names chart.add(prefix, counts) save_name = os.path.join(dir_name, file_name + ".svg") chart.render_to_file(save_name)
def __init__(self): super(DBSize, self).__init__('total-0.png') self.tables_size = {} self.total_size = {} self.lines_count_size = {} self.mean_lines_size = {} self.pygal_config = Config() self.pygal_config.human_readable = True self.pygal_config.legend_box_size = 24 self.pygal_config.show_legend = True self.pygal_config.show_values = True self.pygal_config.style = SolidColorStyle self.pygal_config.style.colors = ['#ff3000', '#ff8900', '#ffe500', \ '#b7ff3f', '#66ff90', '#18ffdd', '#00a4ff', '#0040ff', '#0000ec', '#00007f'] self.pygal_config.style.opacity = '.9' self.pygal_config.style.opacity_hover = '.4' self.pygal_config.style.transition = '100ms ease-in' self.pygal_config.truncate_legend = 9999999
def make_buildmd(allmetadata, fullreport, reportFile, metadataFolder): """ Creates several plots from some metadata and a report.md markdown file embedding the plots. """ allmetadata = pd.DataFrame(allmetadata) import pygal from pygal.style import CleanStyle from pygal.style import Style mystyle = CleanStyle(font_family="sans-serif") # Pygal chart configuration from pygal import Config config = Config() config.legend_at_bottom = True config.legend_at_bottom_columns = 3 config.print_values = True config.style = mystyle #config.width=500 #config.height=300 config.font_family = "Arial" # Donut chart for author genders genders = dict(Counter(allmetadata.loc[:, "au-gender"])) chart = pygal.Pie(config, title="Number of novels per author gender", inner_radius=.60, font_family="sans-serif") chart.add("male", genders["M"]) chart.add("female", genders["F"]) chart.add("other", 0) chart.render_to_file(join(metadataFolder, "au-genders.svg")) # Bar chart for time periods timeslots = dict(Counter(allmetadata.loc[:, "time-slot"])) chart = pygal.Bar(config, range=(0, 30), title="Number of novels per 20-year period", font_family="sans-serif", legend_at_bottom_columns=4) chart.add("1840-1859", timeslots["T1"]) chart.add("1860-1879", timeslots["T2"]) chart.add("1880-1899", timeslots["T3"]) chart.add("1900-1919", timeslots["T4"]) chart.render_to_file(join(metadataFolder, "timeslots.svg")) # Save report.md with embedded charts reportmd = "## Corpus composition for ELTeC-fra\n\n<img src=\"/Metadata/au-genders.svg\">\n<img src=\"/Metadata/timeslots.svg\">" with open(reportFile, "w", encoding="utf8") as outfile: outfile.write(reportmd)
def __init__(self, path='/tmp/graph.png', locale=None, extra_css=None): # Mutable list extra_css used as default argument to a method or function extra_css = extra_css or [] self.style = None self.chart = None self.path = path # Mutable dict locale used as default argument to a method or function self.locale = locale or {} self.locale = locale self.config = Config() self.config.no_data_text = 'No result found' self.config.no_data_font_size = 13 self.config.x_label_rotation = 45 self.config.truncate_legend = 255 self.config.truncate_label = 255 for css in extra_css: self.config.css.append(css) if 'STR_NODATA' in self.locale: self.config.no_data_text = self.locale['STR_NODATA']
def test_css(Chart): """Test css file option""" css = "{{ id }}text { fill: #bedead; }\n" with NamedTemporaryFile('w') as f: f.write(css) f.flush() config = Config() config.css.append('file://' + f.name) chart = Chart(config) chart.add('/', [10, 1, 5]) svg = chart.render().decode('utf-8') assert '#bedead' in svg chart = Chart(css=(_ellipsis, 'file://' + f.name)) chart.add('/', [10, 1, 5]) svg = chart.render().decode('utf-8') assert '#bedead' in svg
def get_sale_chart(self, stat, df): config = Config() config.show_legend = False config.human_readable = True # config.fill = True config.x_label_rotation = 90 config.pretty_print = True config.min_scale = 12 config.height = 480 # config.print_values = True # config.print_values_position = 'top' # config.value_font_size=30 sale_chart = pygal.Line(config) sale_chart.title = '销量与销售额' sale_chart.x_labels = map( lambda x: x.date_created.strftime("%Y-%m-%d"), stat) price_se = df.price.convert_objects(convert_numeric=True) sale_se = df.sale_num.diff().fillna(0) sale_chart.add('销量', [row for row in sale_se]) sale_chart.add('销售额', [row for row in price_se.mul(sale_se)], secondary=True) # return sale_chart.render() return sale_chart.render_data_uri()
class Chart(object): Y_AXIS_MULTIPLIER = 1.33 # The default style settings for a bart chart or histogram BAR_CONFIG = Config() BAR_CONFIG.legend_box_size = 15 BAR_CONFIG.width = 1000 BAR_CONFIG.legend_at_bottom = True BAR_CONFIG.truncate_legend = -1 BAR_CONFIG.max_scale = 7 BAR_CONFIG.print_values = True BAR_CONFIG.print_values_position = 'top' BAR_CONFIG.style = DefaultStyle(background='#fff', title_font_size=20) # Shared init stuff among all chart types def __init__(self, title): self.chart.title = title self.chart.range = (0, self.max_y_axis) # Output a chart to png def render_png(self, chart_name): self.chart.render_to_png('app/static/charts/{}.png'.format(chart_name))
def renderMetricsGraph(self,metric): if metric: aStyle = DefaultStyle(font_family='Arial',colors=self.getColors(),background='rgba(255,255,255,1)') config = Config() config.y_title = '' config.truncate_legend = 50 config.x_title = 'Percent' config.y_labels = (10, 20, 30, 40, 50, 60, 70, 80, 90, 100) config.human_readable = True bar_chart = pygal.HorizontalBar(config,style=aStyle) bar_chart.title = metric.get('description','') bar_chart.add('Responded %s' % (metric.get('pctHasResponse').strip()) + '%', float(metric.get('pctHasResponse'))) bar_chart.add('No Response %s' % (metric.get('pctNoResponse').strip()) + '%', float(metric.get('pctNoResponse'))) bar_chart.add('Approved %s' % (metric.get('pctApproved').strip()) + '%', float(metric.get('pctApproved'))) bar_chart.add('Declined %s' % (metric.get('pctDeclined').strip()) + '%', float(metric.get('pctDeclined'))) bar_chart.add('Denied %s' % (metric.get('pctDenied').strip()) + '%', float(metric.get('pctDenied'))) return bar_chart.render() return ''
def draw_position(groups, filename="position.svg", dir="images", drawSource=True, drawReceptors=True): ''' plot sources' and receptors' position ''' from pygal import Config config = Config() config.title = "Position" config.show_lengend = False config.height = 500 config.stroke = False config.dots_size = 2.5 plot = pygal.XY(config, x_title="X/m", y_title="Y/m", show_x_guides=True, print_labels=True, style=pygal.style.styles["default"](value_font_size=2)) if drawSource: src = groups.sourceInfo meta = [] for line in src: name = line[0] coor = line[1:3].astype(float) * 1000 meta.append({'value': tuple(coor), 'label': name}) plot.add("sources", meta) if drawReceptors: recep = groups.receptors meta = [] for line in recep: name = line[0] coor = line[1:3].astype(float) * 1000 meta.append({'value': tuple(coor), 'label': name, 'dots_size': 2}) plot.add("receptors", meta) plot.render_to_file(pathlib.Path(dir) / filename)
def pygal_line_plot(self, vars: list) -> None: """ build and save line plot in pygal :param vars: list of the y vars in the graph """ if not self.data: self.no_data_message = Markup("""<p>No data available</p>""") else: # Pygal config config = Config() config.show_legend = True config.include_x_axis = False config.stroke_style = {'width': 7} config.dots_size = 8 config.x_label_rotation = -45 # init graph graph = pygal.Bar(config, margin_top=10, range=(1, 5), style=self.pygal_line_style, legend_at_bottom=True, legend_box_size=20, truncate_legend=-1) # init data revered_df = self.pandas_df.sort_values('date', ascending=True) dates = [x.strftime('%Y-%m-%d') for x in list(revered_df['date'])] graph.x_labels = dates print(graph.x_labels) for var in vars: print(var) data = list(revered_df[var]) graph.add('{} lvl'.format(var), data) path = os.path.join(os.getcwd(),'health_tracker', 'static') if \ os.getcwd().endswith('health_tracker') else \ os.path.join(os.getcwd(),'health_tracker', 'health_tracker', 'static') graph.render_to_file( os.path.join(path, '{}_line_graph.svg'.format(self.name)))
def pie(data, inner_radius=0): config = Config() #config.show_legend = False config.height = 300 config.width = 300 #config.print_values=True #config.print_labels=True #config.half_pie=True config.value_formatter = lambda x: f'{x}%' # config.style= RedBlueStyle( # value_font_size=15, # value_label_font_size=15, # value_colors=()) #config.legend_at_bottom=True #config.legend_at_bottom_columns=3 config.dynamic_print_values = True config.inner_radius = inner_radius graph = pygal.Pie(config, title="Number of Dogs Owned") for item in data: graph.add(item, data[item]) #[{'value': data[item], 'label':item}]) graph_data = graph.render_data_uri() return graph_data
def drawcapitalcostcomponentsfigure(techlist): config = Config() config.show_legend = True config.human_readable = True config.dots_size = 3 config.x_label_rotation = 270 config.legend_at_bottom = True config.x_title = "capital cost of power based components [$/kW]" config.y_title = "capital cost of energy based components [$/kWh]" #config.show_dots = False config.fill = True #config.show_minor_x_labels = False config.stroke_style = {'width': 1} config.style = pygal.style.styles['default']( label_font_size=12, stroke_opacity=0, stroke_opacity_hover=0, transition='100000000000s ease-in') xy_chart = pygal.XY(config) xmin = 10000 ymin = 10000 xmax = 0.001 ymax = 0.001 for tech in techlist: power_minstring = "capital_cost_of_power_based_components_min" power_maxstring = "capital_cost_of_power_based_components_max" energy_minstring = "capital_cost_of_energy_based_components_min" energy_maxstring = "capital_cost_of_energy_based_components_max" minpowerlink = '' maxpowerlink = '' minenergylink = '' maxenergylink = '' minpowerlabel = '' maxpowerlabel = '' minenergylabel = '' maxenergylabel = '' if Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=power_minstring). first().source_id).first() is not None: minpowerlink = Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=power_minstring).first().source_id).first().link minpowerlabel = 'min. cost of power based components: ' + Source.query.filter_by( id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=power_minstring). first().source_id).first().author + ', ' + str( Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=power_minstring).first().source_id).first(). releaseyear) if Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=power_maxstring). first().source_id).first() is not None: maxpowerlink = Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=power_maxstring).first().source_id).first().link maxpowerlabel = 'max. cost of power based components: ' + Source.query.filter_by( id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=power_maxstring). first().source_id).first().author + ', ' + str( Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=power_maxstring).first().source_id).first(). releaseyear) if Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=energy_minstring). first().source_id).first() is not None: minenergylink = Source.query.filter_by( id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=energy_minstring).first().source_id).first().link minenergylabel = 'min. cost of energy based components: ' + Source.query.filter_by( id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=energy_minstring) .first().source_id).first().author + ', ' + str( Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=energy_minstring).first().source_id).first(). releaseyear) if Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=energy_maxstring). first().source_id).first() is not None: maxenergylink = Source.query.filter_by( id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=energy_maxstring).first().source_id).first().link maxenergylabel = 'max. cost of energy based components: ' + Source.query.filter_by( id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=energy_maxstring) .first().source_id).first().author + ', ' + str( Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=energy_maxstring).first().source_id).first(). releaseyear) xy_chart.add(f"{tech.name}", [{ 'value': (Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_minstring).first().value, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_minstring).first().value), 'label': minenergylabel, 'xlink': { 'href': minenergylink, 'target': '_blank' } }, { 'value': (Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_minstring).first().value, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_maxstring).first().value), 'label': minpowerlabel, 'xlink': { 'href': minpowerlink, 'target': '_blank' } }, { 'value': (Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_maxstring).first().value, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_maxstring).first().value), 'label': maxenergylabel, 'xlink': { 'href': maxenergylink, 'target': '_blank' } }, { 'value': (Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_maxstring).first().value, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_minstring).first().value), 'label': maxpowerlabel, 'xlink': { 'href': maxpowerlink, 'target': '_blank' } }, { 'value': (Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_minstring).first().value, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_minstring).first().value), 'label': minenergylabel, 'xlink': { 'href': minenergylink, 'target': '_blank' } }]) if Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_minstring).first().value is not None: xmin = min( xmin, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_minstring).first().value) xmax = max( xmax, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_maxstring).first().value) if Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_minstring).first().value is not None: ymin = min( ymin, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_minstring).first().value) ymax = max( ymax, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_maxstring).first().value) xup = 10**int(math.floor(math.log10(xmax))) yup = 10**int(math.floor(math.log10(ymax))) while xup < xmax: xup = xup + 10**int(math.floor(math.log10(xmax))) while yup < ymax: yup = yup + 10**int(math.floor(math.log10(ymax))) xy_chart.xrange = (10**int(math.floor(math.log10(xmin))), xup) xy_chart.range = (10**int(math.floor(math.log10(ymin))), yup) xy_chart.render() return xy_chart.render_data_uri()
def drawdensityfigure(techlist, par): config = Config() config.show_legend = True config.human_readable = True config.dots_size = 3 config.x_label_rotation = 270 config.legend_at_bottom = True if par == "gravimetric": power_unit = "[W/kg]" energy_unit = "[Wh/kg]" else: power_unit = "[kW/m^3]" energy_unit = "[kWh/m^3]" config.x_title = par + " power density " + power_unit config.y_title = par + " energy density " + energy_unit #config.show_dots = False config.logarithmic = True config.fill = True #config.show_minor_x_labels = False config.stroke_style = {'width': 1} config.style = pygal.style.styles['default']( label_font_size=12, stroke_opacity=0, stroke_opacity_hover=0, transition='100000000000s ease-in') xy_chart = pygal.XY(config) xmin = 10000 ymin = 10000 xmax = 0.001 ymax = 0.001 for tech in techlist: power_minstring = par + "_power_density_min" power_maxstring = par + "_power_density_max" energy_minstring = par + "_energy_density_min" energy_maxstring = par + "_energy_density_max" minpowerlink = '' maxpowerlink = '' minenergylink = '' maxenergylink = '' minpowerlabel = '' maxpowerlabel = '' minenergylabel = '' maxenergylabel = '' if Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=power_minstring). first().source_id).first() is not None: minpowerlink = Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=power_minstring).first().source_id).first().link minpowerlabel = 'min. power density: ' + Source.query.filter_by( id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=power_minstring). first().source_id).first().author + ', ' + str( Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=power_minstring).first().source_id).first(). releaseyear) if Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=power_maxstring). first().source_id).first() is not None: maxpowerlink = Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=power_maxstring).first().source_id).first().link maxpowerlabel = 'max. power density: ' + Source.query.filter_by( id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=power_maxstring). first().source_id).first().author + ', ' + str( Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=power_maxstring).first().source_id).first(). releaseyear) if Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=energy_minstring). first().source_id).first() is not None: minenergylink = Source.query.filter_by( id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=energy_minstring).first().source_id).first().link minenergylabel = 'min. energy density: ' + Source.query.filter_by( id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=energy_minstring) .first().source_id).first().author + ', ' + str( Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=energy_minstring).first().source_id).first(). releaseyear) if Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=energy_maxstring). first().source_id).first() is not None: maxenergylink = Source.query.filter_by( id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=energy_maxstring).first().source_id).first().link maxenergylabel = 'max. energy density: ' + Source.query.filter_by( id=Parameter.query.filter_by( technology_name=tech.name).filter_by(name=energy_maxstring) .first().source_id).first().author + ', ' + str( Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=energy_maxstring).first().source_id).first(). releaseyear) xy_chart.add(f"{tech.name}", [{ 'value': (Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_minstring).first().value, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_minstring).first().value), 'label': minenergylabel, 'xlink': { 'href': minenergylink, 'target': '_blank' } }, { 'value': (Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_minstring).first().value, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_maxstring).first().value), 'label': minpowerlabel, 'xlink': { 'href': minpowerlink, 'target': '_blank' } }, { 'value': (Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_maxstring).first().value, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_maxstring).first().value), 'label': maxenergylabel, 'xlink': { 'href': maxenergylink, 'target': '_blank' } }, { 'value': (Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_maxstring).first().value, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_minstring).first().value), 'label': maxpowerlabel, 'xlink': { 'href': maxpowerlink, 'target': '_blank' } }, { 'value': (Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_minstring).first().value, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_minstring).first().value), 'label': minenergylabel, 'xlink': { 'href': minenergylink, 'target': '_blank' } }]) if Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_minstring).first().value is not None: xmin = min( xmin, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_minstring).first().value) xmax = max( xmax, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=power_maxstring).first().value) if Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_minstring).first().value is not None: ymin = min( ymin, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_minstring).first().value) ymax = max( ymax, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=energy_maxstring).first().value) xy_chart.xrange = (10**int(math.floor(math.log10(xmin))), 10**(int(math.floor(math.log10(xmax))) + 1) + 1) xy_chart.range = (10**int(math.floor(math.log10(ymin))), 10**(int(math.floor(math.log10(ymax))) + 1) + 1) xy_chart.render() return xy_chart.render_data_uri()
def test_config_behaviours(): """Test that all different way to set config produce same results""" line1 = Line() line1.show_legend = False line1.fill = True line1.pretty_print = True line1.no_prefix = True line1.x_labels = ['a', 'b', 'c'] line1.add('_', [1, 2, 3]) l1 = line1.render() q = line1.render_pyquery() assert len(q(".axis.x")) == 1 assert len(q(".axis.y")) == 1 assert len(q(".plot .series path")) == 1 assert len(q(".legend")) == 0 assert len(q(".x.axis .guides")) == 3 assert len(q(".y.axis .guides")) == 11 assert len(q(".dots")) == 3 assert q(".axis.x text").map(texts) == ['a', 'b', 'c'] line2 = Line( show_legend=False, fill=True, pretty_print=True, no_prefix=True, x_labels=['a', 'b', 'c']) line2.add('_', [1, 2, 3]) l2 = line2.render() assert l1 == l2 class LineConfig(Config): show_legend = False fill = True pretty_print = True no_prefix = True x_labels = ['a', 'b', 'c'] line3 = Line(LineConfig) line3.add('_', [1, 2, 3]) l3 = line3.render() assert l1 == l3 line4 = Line(LineConfig()) line4.add('_', [1, 2, 3]) l4 = line4.render() assert l1 == l4 line_config = Config() line_config.show_legend = False line_config.fill = True line_config.pretty_print = True line_config.no_prefix = True line_config.x_labels = ['a', 'b', 'c'] line5 = Line(line_config) line5.add('_', [1, 2, 3]) l5 = line5.render() assert l1 == l5 l6 = Line(line_config)(1, 2, 3, title='_').render() assert l1 == l6
global clients global activeClients global loadAvg15Min global loadAvg5Min global loadAvg1Min global MemUsage global diskUsage global sender global receivers sender = 'Monito admin <*****@*****.**>' receivers = ['*****@*****.**'] config = Config() config.range=(.0001, 5) config.legend_font_size=30 config.tooltip_font_size=30 config.legend_box_size=18 config.title_font_size=30 config.label_font_size=20 config.legend_at_bottom=True config.major_label_font_size=20 config.no_data_text='Fetching data..' config1 = Config() config1.fill=True config1.spacing=50 config1.range=(1, 100) config1.legend_font_size=30
def drawfigure(techlist, par): config = Config() config.show_legend = False config.xrange = (0, len(techlist) + 1) #labels, dots and stroke depending on number of technologies compared config.dots_size = 7 config.stroke_style = {'width': 50} labelsize = 12 if len(techlist) > 3: config.truncate_label = 20 config.x_label_rotation = 20 config.dots_size = 6 config.stroke_style = {'width': 40} if len(techlist) > 5: config.dots_size = 5 config.stroke_style = {'width': 30} if len(techlist) > 10: config.stroke_style = {'width': 27} if len(techlist) > 13: config.dots_size = 4 config.stroke_style = {'width': 25} if len(techlist) > 15: config.dots_size = 4 config.stroke_style = {'width': 22} labelsize = 11 if len(techlist) > 17: config.dots_size = 3 config.stroke_style = {'width': 20} if len(techlist) > 20: labelsize = 10 config.stroke_style = {'width': 18} if len(techlist) > 23: labelsize = 9 config.stroke_style = {'width': 15} if len(techlist) > 27: labelsize = 8 config.stroke_style = {'width': 14} if len(techlist) > 31: labelsize = 7 config.stroke_style = {'width': 12} config.human_readable = True unit = Parameter.query.filter_by(name=par + '_min').first().unit config.y_title = par.replace('_', ' ') + ' [' + unit + ']' #config.show_dots = False config.style = pygal.style.styles['default']( stroke_opacity=1, label_font_size=labelsize, stroke_opacity_hover=1, transition='100000000000s ease-in') if par == 'efficiency': config.range = (0, 100) xy_chart = pygal.XY(config) if par == 'discharge_time': xy_chart.y_labels = [{ 'label': 'milliseconds', 'value': 1 }, { 'label': 'seconds', 'value': 2 }, { 'label': 'minutes', 'value': 3 }, { 'label': 'hours', 'value': 4 }, { 'label': 'days', 'value': 5 }, { 'label': 'weeks', 'value': 6 }, { 'label': 'months', 'value': 7 }] if par == 'response_time': xy_chart.y_labels = [{ 'label': 'milliseconds', 'value': 1 }, { 'label': 'seconds', 'value': 2 }, { 'label': 'minutes', 'value': 3 }] dictlist = [] ymin = 100000000000 ymax = 0 logscale = False for tech in techlist: if Parameter.query.filter_by(technology_name=tech.name).filter_by( name=par + "_min").first().value != None: ymin = min( Parameter.query.filter_by(technology_name=tech.name).filter_by( name=par + "_min").first().value, ymin) ymax = max( Parameter.query.filter_by(technology_name=tech.name).filter_by( name=par + "_max").first().value, ymax) if (ymin * 100) < ymax: xy_chart.logarithmic = True xy_chart.xrange = (0, 10**(len(techlist) + 1)) if ymax < 100000: xy_chart.range = (10**int(math.floor(math.log10(ymin))), 10**(int(math.floor(math.log10(ymax))) + 1) + 1) else: xy_chart.range = (10**int(math.floor(math.log10(ymin))), 10**(int(math.floor(math.log10(ymax)))) + 1) logscale = True if logscale: i = 10 else: i = 1 for tech in techlist: minxlink = '' maxxlink = '' minlabel = '' maxlabel = '' if Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=par + "_min").first().source_id).first() is not None: minxlink = Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=par + "_min").first().source_id).first().link minlabel = Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=par + "_min").first().source_id).first().author + ', ' + str( Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=par + "_min").first().source_id).first().releaseyear) if Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=par + "_max").first().source_id).first() is not None: maxxlink = Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=par + "_max").first().source_id).first().link maxlabel = Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=par + "_max").first().source_id).first().author + ', ' + str( Source.query.filter_by(id=Parameter.query.filter_by( technology_name=tech.name).filter_by( name=par + "_max").first().source_id).first().releaseyear) xy_chart.add(f"{tech.name}", [{ 'value': (i, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=par + "_min").first().value), 'label': minlabel, 'xlink': { 'href': minxlink, 'target': '_blank' } }, { 'value': (i, Parameter.query.filter_by(technology_name=tech.name).filter_by( name=par + "_max").first().value), 'label': maxlabel, 'xlink': { 'href': maxxlink, 'target': '_blank' } }]) dictlist.append({'label': f"{tech.name}", 'value': i}) if logscale: i = i * 10 else: i = i + 1 xy_chart.x_labels = (dictlist) xy_chart.x_value_formatter = lambda x: "" xy_chart.render() return xy_chart.render_data_uri()
def using_pygal(DataFile): print("--using_pygal...") # Get the data as dataframe RightData = mold_data(DataFile) # Remove unnecessary information RightData = RightData.drop("edit-no", axis=1) RightData = RightData.drop("type", axis=1) RightData = RightData.drop("analysis", axis=1) RightData = RightData.drop("char-diff", axis=1) RightData = RightData.drop("char-diff-abs", axis=1) # RightData1: set levenshtein to zero for substantives (effectively ignoring them) RightData1 = RightData.copy(deep=True) RightData1.loc[RightData1["category"] =="other","levenshtein"] = 0 # Fix some details: levenshtein as numerical, remove x from line-id RightData1["levenshtein"] = RightData1["levenshtein"].astype(str).convert_objects(convert_numeric=True) RightData1["line-id"] = RightData1["line-id"].map(lambda x: x.rstrip("x")) RightData1 = RightData1.groupby("line-id").sum() #print(RightData1.head(20)) # RightData2: set levenshtein to zero for copyedits (effectively ignoring them) RightData2 = RightData.copy(deep=True) RightData2.loc[RightData2["category"] =="copyedit","levenshtein"] = 0 # Fix some details: levenshtein as numerical, remove x from line-id RightData2["levenshtein"] = RightData2["levenshtein"].astype(str).convert_objects(convert_numeric=True) RightData2["line-id"] = RightData2["line-id"].map(lambda x: x.rstrip("x")) RightData2 = RightData2.groupby("line-id").sum() #print(RightData2.head(20)) # Select the range of data we want Lines = RightData1.index.values Copyedits = RightData1.loc[:,"levenshtein"] Substantives = RightData2.loc[:,"levenshtein"] # Apply some interpolation CopyeditsSF = sf(Copyedits, 35, 1, mode="nearest") SubstantivesSF = sf(Substantives, 35, 1, mode="nearest") # Graph general configuration config = Config() config.show_legend = False config.human_readable = True config.fill = False # Line chart LineChart = pygal.StackedLine(config, height=1000, width = 2000, x_label_rotation=300, show_legend=False, x_labels_major_every=200, show_minor_x_labels=False, show_dots=False, fill=True, logarithmic=False, range=(0, 60)) LineChart.title ="The Martian Modifications (copyedits and substantives)" LineChart.y_title = "Levenshtein distance (smoothed)" LineChart.x_title = "Lines in the novel" LineChart.x_labels = Lines LineChart.add("Copyedits", CopyeditsSF) LineChart.add("Substantives", SubstantivesSF) LineChart.render_to_file("MartianMods_copyedits+substantives.svg")
"""Render graph svg file""" import pygal from pygal import Config import requests config = Config() config.show_legend = True config.human_readable = True def main(): """Render Maps with total population in the world""" worldmap_chart = pygal.maps.world.World(print_labels = True) worldmap_chart.title = 'Total Population in each Contries' country = {'Afghanistan':'af', 'Albania':'al', 'Algeria':'dz', 'Angola':'ao',\ 'Azerbaijan':'az', 'Argentina':'ar', 'Australia':'au', 'Austria':'at', \ 'Bahrain':'bh', 'Bangladesh':'bd', 'Armenia':'am', 'Belgium':'be', \ 'Bhutan':'bt', 'Bolivia':'bo', 'Bosnia and Herzegovina':'ba', \ 'Botswana':'bw', 'Brazil':'br', 'Belize':'bz', 'Brunei Darussalam':'bn', \ 'Bulgaria':'bg', 'Myanmar':'mm', 'Burundi':'bi', 'Belarus':'by', \ 'Cambodia':'kh', 'Cameroon':'cm', 'Canada':'ca', 'Cabo Verde':'cv', \ 'Central African Republic':'cf', 'Sri Lanka':'lk', 'Chad':'td', 'Chile':'cl', \ 'China':'cn', 'Colombia':'co', 'Mayotte':'yt', 'Congo':'cg', \ 'Dem Rep of Congo':'cd', 'Costa Rica':'cr', 'Croatia':'hr', 'Cuba':'cu', \ 'Cyprus':'cy', 'Czech Republic':'cz', 'Benin':'bj', 'Denmark':'dk', \ 'Dominican Republic':'do', 'Ecuador':'ec', 'El Salvador':'sv', \ 'Equatorial Guinea':'eq', 'Ethiopia':'et', 'Eritrea':'er', 'Estonia':'ee', \ 'Finland':'fi', 'France':'fr', 'French Guiana':'gf', 'Djibouti':'dj', \ 'Gabon':'ga', 'Georgia':'ge', 'The Gambia':'gm', 'Germany':'de', 'Ghana':'gh', \ 'Greece':'gr', 'Guam':'gu', 'Guatemala':'gt', 'Guinea':'gw', 'Guyana':'gy', \ 'Haiti':'ht', 'Honduras':'hn', 'Hong Kong SAR-China':'hk', 'Hungary':'hu', \ 'Iceland':'is', 'India':'in', 'Indonesia':'id', 'Islamic Republic of Iran':'ir', \
def genfoodchart(start, end): '''Generate food chart with Pygal''' now = datetime.datetime.now().strftime("%Y-%m-%d") goodcount = session.query(Food) \ .filter_by(user_id=current_user.id) \ .filter(Food.food_date.between(start, end)).join(Ranks) \ .filter_by(rank=1).add_columns(Ranks.rank).count() okaycount = session.query(Food) \ .filter_by(user_id=current_user.id) \ .filter(Food.food_date.between(start, end)).join(Ranks) \ .filter_by(rank=2).add_columns(Ranks.rank).count() badcount = session.query(Food) \ .filter_by(user_id=current_user.id) \ .filter(Food.food_date.between(start, end)).join(Ranks) \ .filter_by(rank=3).add_columns(Ranks.rank).count() custom_style = Style( background='transparent', value_font_size=24, title_font_size=36, margin=1, plot_background='transparent', foreground='#53E89B', foreground_strong='#53A0E8', foreground_subtle='#630C0D', opacity='.6', opacity_hover='.9', transition='400ms ease-in', colors=('#5cb85c', '#f0ad4e', '#d9534f')) config = Config() config.show_legend = True config.legend_at_bottom=True config.legend_at_bottom_columns=1 config.legend_box_size=10 config.human_readable = True config.fill = True config.style=custom_style config.print_labels=True config.print_values=True config.no_data_text='Need to add some food!' pie_chart = pygal.Pie(config) pie_chart.title = "Current Food Stats" pie_chart.add('Good', goodcount) pie_chart.add('Okay', okaycount) pie_chart.add('Bad', badcount) chart = pie_chart.render(is_unicode=True) return chart
def __prepareSVGConfigGeneric(colors): config = Config() config.show_legend = True config.human_readable = True config.fill = True config.order_min = 0 config.x_label_rotation = 80 config.margin = 80 config.legend_font_size = 10 config.tooltip_border_radius = 10 config.legend_font_size = 10 config.no_data_text = "No changes found" config.style = Style(background='transparent', plot_background='#f5f5f5', foreground='#428bca', foreground_light='#000000', foreground_dark='#428bca', opacity='.6', opacity_hover='.9', transition='400ms ease-in', colors=colors) return config
# if nMaxDataCount > 0: # # Check if we need to reduce the data amount # nTotalDataCount = len( aData[aFields[0]] ) # nDataStepCount = nTotalDataCount / (nMaxDataCount) # if nTotalDataCount > nMaxDataCount: # for iDataNum in reversed(range(0, nTotalDataCount)): # # Remove all entries who # if iDataNum % nDataStepCount == 0: # aMajorXData.append( aData[aFields[0]][iDataNum] ) # Import Style # from pygal.style import LightSolarizedStyle # Create Config object from pygal import Config chartCfg = Config() chartCfg.show_legend = True chartCfg.human_readable = True chartCfg.pretty_print=True if bFilledLineChart: chartCfg.fill = True else: chartCfg.fill = False chartCfg.x_scale = 1 chartCfg.y_scale = 1 chartCfg.x_label_rotation = 45 chartCfg.include_x_axis = True chartCfg.show_dots=False if nMaxDataCount > 0: chartCfg.show_minor_x_labels=False chartCfg.x_labels_major_count=nMaxDataCount
def identify(self, filename): self.report["filename"] = os.path.basename(filename) self.report["filename_absolute"] = filename self.report["filemimetype"] = utils.file_mimetype(filename) self.report["filemagic"] = utils.file_magic(filename) if self.report["filemimetype"] in self.pcapmimetypes: self.report["filecategory"] = "CAP" self.report["filetype"] = "PCAP" self.logger.info( "Identified %s as type %s (%s)" % (self.report["filename"], self.report["filetype"], self.report["filemimetype"]) ) else: self.logger.info( "File %s of type %s is not supported in the current version" % (self.report["filename"], self.report["filemimetype"]) ) return None self.logger.debug("Calculating file hashes for %s" % (self.report["filename"])) self.report["hashes"]["crc32"] = utils.file_hashes(filename, "crc32") self.report["hashes"]["md5"] = utils.file_hashes(filename, "md5") self.report["hashes"]["sha1"] = utils.file_hashes(filename, "sha1") self.report["hashes"]["sha256"] = utils.file_hashes(filename, "sha256") self.report["hashes"]["sha512"] = utils.file_hashes(filename, "sha512") self.report["hashes"]["ssdeep"] = utils.file_hashes(filename, "ssdeep") self.logger.info("Completed crc32/md5/sha{1,256,512}/ssdeep hash calculations") if self.config["enable_entropy_compression_stats"]: self.logger.debug("Collecting entropy compression stats for %s" % (self.report["filename"])) stats = utils.entropy_compression_stats(filename) self.report["filesize"] = stats["filesizeinbytes"] self.report["fileminsize"] = float(stats["minfilesize"]) self.report["filecompressionratio"] = float(stats["compressionratio"]) self.report["fileentropy"] = float(stats["shannonentropy"]) # if entropy falls within the 0 - 1 or 7 - 8 range, categorize as suspicious if (self.report["fileentropy"] > 0 and self.report["fileentropy"] < 1) or self.report["fileentropy"] > 7: self.report["fileentropy_category"] = "SUSPICIOUS" else: self.report["fileentropy_category"] = "NORMAL" self.logger.info("Completed entropy compression stats collection") else: stats = {} if self.config["enable_bytefreq_histogram"]: self.logger.debug("Generating Byte-Frequency histogram for %s" % (self.report["filename"])) config = Config() config.x_title = "Bytes" config.y_title = "Frequency" config.x_scale = 0.25 config.y_scale = 0.25 config.width = 900 config.height = 300 config.title_font_size = 9 config.tooltip_font_size = 0 config.tooltip_border_radius = 0 config.no_data_text = "" config.show_legend = False config.show_only_major_dots = True config.human_readable = False config.show_y_labels = False config.fill = True config.style = CleanStyle bar_chart = pygal.Bar(config) if "bytefreqlist" in stats.keys(): bar_chart.add("", stats["bytefreqlist"]) self.report["filebytefreqhistogram"] = bar_chart.render(is_unicode=False) self.logger.info("Completed Byte-Frequency histogram generation") # testing and db support to identify visually similar files/sessions if self.config["enable_file_visualization"]: self.logger.debug("Generating file visualization for %s" % (self.report["filename"])) self.report["filevis_png"] = utils.file_to_pngimage(filename) self.report["filevis_png_bw"] = utils.file_to_pngimage(filename, enable_colors=False) self.logger.info("Completed file visualization generation") return dict(self.report)
foreground='black', foreground_strong='black', foreground_subtle='#0B6121', legend_font_size=15, title_font_size=20, legend_box_size=20, colors=('#04B404', 'green', 'green', 'green')) #Style für die Top20 Weltkarten world_style2 = Style( background='transparent', plot_background='#f0efff', title_font_size=17,) #Diagramm-Einstellungen config = Config() config.rounded_bars=5 config.legend_box_size=20 config.x_label_rotation=90 config.fill=True #Horizontales Histogramm mit Vergleich zwischen Installationszahlen 2015 und 2016 chart = pygal.HorizontalBar(style=chart_style1,legend_box_size=20) chart.title = 'Installationen 2015 und 2016' chart.add('2015', summe_installs_2015, rounded_bars=5) chart.add('2016', summe_installs_2016, rounded_bars=5) chart.render_to_file('charts/installs_compared_2015_2016.svg') #Kreisdiagramm mit Deinstallations- und "Behalten"-Quote von 2015 pie_chart = pygal.Pie(style=chart_style1,legend_box_size=20) pie_chart.title = 'Deinstallationsquote 2015'
return rec['decom'] + '-' + str(rec['N']) def decom(rec): return rec['decom'].upper() if __name__ == '__main__': # Read in CSV report, strip the headers, blank lines print(colored('Reading CSV report ...','cyan')) csv = read_csv(args['from']) data_1, data_2, data_3 = tee(gen_csv(csv),3) # Make a renderable radar # where the `decomposition algorithms` are plotted on X (corners of Radar) # and `variations of parameters` are plotted on Y (contour lines) print(colored('Preparing radar ...','cyan')) cfg = Config() cfg.fill = True radar = pygal.Radar(cfg, range=(70,85)) radar.title = 'Clustering/Feature Comparison' bar = {} # Bar charts, indexed by cluster type # NOTE: Need to do the loop, not the `set` conversion # otherwise the list gets sorted which becomes out of sync labels = [] for n in data_1: if label(n) not in labels: labels.append(label(n)) # Create a bar chart for each of the cluster type bar[label(n)] = pygal.HorizontalBar(cfg, range=(70,90)) bar[label(n)].title = 'Cluster with ' + label(n).upper() radar.x_labels = labels
def using_pygal(DataFile): print("using_pygal...") ## Getting the data with open(DataFile, "r") as infile: AllData = pd.read_table(infile) #print(AllData.head()) # Select the data we want Lines = AllData.loc[:,"line-no"][0:50] ItemIDs = AllData.loc[:,"item-id"][0:50] Version1s = AllData.loc[:,"version1"][0:50] Version2s = AllData.loc[:,"version2"][0:50] Categories = AllData.loc[:,"category"][0:50] Types = AllData.loc[:,"type"][0:50] LevDists = AllData.loc[:,"levenshtein"][0:50] CharDiffsAbs = AllData.loc[:,"char-delta-abs"][0:50] CharDiffs = AllData.loc[:,"char-delta"][0:50] # Apply very simple smoothing to LevDists LevDistsSmth = [] Smthp0 = (LevDists[0] + LevDists[1])/2 Smthp1 = (LevDists[1] + LevDists[2])/2 LevDistsSmth.append(Smthp0) LevDistsSmth.append(Smthp1) for i in range(2, len(LevDists)-2): NewValue = (LevDists[i-2]/2 + LevDists[i-1] + LevDists[i] + LevDists[i+1] + LevDists[i+2]/2) / 4 LevDistsSmth.append(NewValue) Smthm0 = (LevDists[len(LevDists)-2] + LevDists[len(LevDists)-3]) / 2 Smthm1 = (LevDists[len(LevDists)-1] + LevDists[len(LevDists)-2]) / 2 LevDistsSmth.append(Smthm0) LevDistsSmth.append(Smthm1) # Graph general configuration config = Config() config.show_legend = False config.human_readable = True config.fill = False # Graphing: bar chart BarChart1 = pygal.Bar(config) BarChart1.title = "The Martian Modifications (Char-Diff)" BarChart1.x_labels = map(str, range(0, 50)) #BarChart.add("Levenshtein", LevDists) BarChart1.add("Char-Diff", CharDiffs) #chart.add("Char-Diff-Abs", CharDiffsAbs) BarChart1.render_to_file("BarChart1.svg") # Graphing: another bar chart BarChart2 = pygal.Bar(config, x_label_rotation=270) BarChart2.title ="The Martian Modifications (Labels)" #LineChart.x_labels = map(str, ItemIDs) for i in range(0,30): BarChart2.add(ItemIDs[i], [{"value" : CharDiffs[i], "label" : str(Version1s[i])+" => "+str(Version2s[i]), 'color': 'red'}]) BarChart2.render_to_file("BarChart2.svg") # Line chart LineChart1 = pygal.Line(config, x_label_rotation=270, show_legend=True) LineChart1.title ="The Martian Modifications (smoothed)" LineChart1.add("LevDists", LevDists) LineChart1.add("LevDistsSmth", LevDistsSmth) LineChart1.render_to_file("LineChart1.svg")