def define_config(): """Defines some configuration settings for the pygal plot.""" config = Config() config.show_legend = False config.human_readable = True config.fill = False config.height = 1000 config.width = 2000 config.x_label_rotation = 300 config.show_legend = False config.x_labels_major_every = 200 # 200 config.show_minor_x_labels = False config.show_dots = False config.fill = True config.logarithmic = False return config
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 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()
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 chartCfg.js = [ 'svg.jquery.js','pygal-tooltips.js' ] # Use script from local # chartCfg.style = LightSolarizedStyle chartCfg.print_values = False chartCfg.print_zeroes = True chartCfg.no_data_text = "All values are 0" if bLogarithmicChart: chartCfg.logarithmic=True # Makes chart Y-Axis data more readable # Create Linechart if bLineChart: myChart = pygal.Line(chartCfg) myChart.title = 'Line Chart of "' + szInput + '"' myChart.x_title = "Time elasped in seconds" myChart.x_labels = map(str, aData[aFields[0]] ) # myChart.x_labels_major = map(str, aMajorXData ) for iChartNum in range(3, len(aFields) ): myChart.add(aFields[iChartNum], aData[ aFields[iChartNum] ]) # Add some values # Create BarChart elif bBarChart: myChart = pygal.Bar(chartCfg) myChart.title = 'Bar Chart of "' + szInput + '"' myChart.x_title = "Time elasped in seconds"
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 #chartCfg.style = DefaultStyle #LightSolarizedStyle chartCfg.style = RotateStyle('#FF0000') chartCfg.print_values = True #False chartCfg.print_zeroes = True chartCfg.no_data_text = "All values are 0" if bLogarithmicChart: chartCfg.logarithmic = True # Makes chart Y-Axis data more readable # remove first item if configured! if bDeltaIgnoreFirstValue: for iChartNum in range(3, len(aFields)): if aCounters is None or aFields[iChartNum] in aCounters: aData[aFields[iChartNum]].pop(0) # Create Linechart if bLineChart: myChart = pygal.Line(chartCfg) myChart.title = 'Line Chart of "' + szChartName + '"' myChart.x_title = "Time elasped in seconds" myChart.x_labels = map(str, aData[aFields[0]]) # myChart.x_labels_major = map(str, aMajorXData ) for iChartNum in range(3, len(aFields)):