def show(data): seleccionados = data.getSeleccionados() #chart = pygal.Line(x_label_rotation=1) # de tipo linea la grafica #chart = pygal.Line() #chart = pygal.bar() # de tipo barras chart = pygal.Line(x_label_rotation=1) #chart.x_labels = Grafica.espaciar(data.getEjeX()) #para añadirle datos al ejex, se ve muy pequeño pero si se pasa el raton se ve bien # Esto es para poner la orientacion dependiendo de donde ubique los datos de tipo temporal if(Linea_pygal.orientacion(data.getSeleccionEjeX())): chart.x_labels = data.getEje(data.getSeleccionEjeX(), 0) # Por que 0? for selec in seleccionados: chart.add(selec, data.getEje(data.getSeleccionEjeY(), selec)) else: chart = pygal.HorizontalLine() chart.x_labels = data.getEje(data.getSeleccionEjeY(), 0)# Por que 0? for selec in seleccionados: chart.add(selec, data.getEje(data.getSeleccionEjeX(), selec)) chart.title = data.getTitle() #chart.x_labels = l.labelsX(l.ejeX()) # no los reconoce como valores asique los apila igual pero como son menos pos quedan todos apretados al principio #chart.render_to_file('output/lineas_pygal.html') chart.render_in_browser() # Si falla el render es porque faltara la libreria lxml
def horizontal_line_chart(): line = pygal.HorizontalLine() line.title = 'HORIZONTAL LINE CHART TEST' line.x_labels = map(str, range(size)) line.add('One', get_increment_data(size)) line.add('Two', get_increment_data(size)) line.render_to_file(get_file_name(inspect.stack()[0][3]))
def pygal_line_horizontal(data, chartname, file_name): line_chart = pygal.HorizontalLine(print_values=True) line_chart.title = chartname for ds in data: for key, value in ds.items(): line_chart.add(key, value) line_chart.render_to_file(file_name + '.svg') line_chart.render_to_png(file_name + '.png') return True
def simple_pygal2(): """与简单线图内容相同,但是图形的X轴与Y轴对调,即原来的X轴移动到垂直方向""" line_chart = pygal.HorizontalLine() line_chart.title = 'Browser usage evolution (in %)' line_chart.x_labels = map(str, range(2002, 2013)) line_chart.add('Firefox', [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1]) line_chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3]) line_chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1]) line_chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5]) line_chart.range = [0, 100] line_chart.render_to_file('simple_pygal2.svg')
def pygal_chart(chart_type, data, chartname, file_name): ''' Funtion builds charts using pygal (pygal.org) python charting library and saves them in .svg and .png format Chart types supported: bar_basic, bar_horizontal, bar_stacked, line_basic, line_horizontal, line_stacked, pie_basic, pie_donut, pie_halfpie, scatter - see http://pygal.org/en/stable/documentation/types/index.html ''' # Define chart type and set some custom styles if chart_type == 'bar_basic': chart = pygal.Bar() chart = pygal.Bar(print_values=True, style=DefaultStyle( value_font_family='googlefont:Raleway', value_font_size=30, value_colors=('white', ))) elif chart_type == 'bar_horizontal': chart = pygal.HorizontalBar() chart = pygal.Bar(print_values=True, style=DefaultStyle( value_font_family='googlefont:Raleway', value_font_size=30, value_colors=('white', ))) elif chart_type == 'bar_stacked': chart = pygal.StackedBar() chart = pygal.Bar(print_values=True, style=DefaultStyle( value_font_family='googlefont:Raleway', value_font_size=30, value_colors=('white', ))) elif chart_type == 'line_basic': chart = pygal.Line(print_values=True) elif chart_type == 'line_horizontal': chart = pygal.HorizontalLine(print_values=True) elif chart_type == 'line_stacked': chart = pygal.StackedLine(fill=True) elif chart_type == 'pie_basic': chart = pygal.Pie() elif chart_type == 'pie_donut': chart = pygal.Pie(inner_radius=.4) elif chart_type == 'pie_halfpie': chart = pygal.Pie(half_pie=True) elif chart_type == 'scatter': chart = pygal.XY(stroke=False) # Add data chart.title = chartname for ds in data: for key, value in ds.items(): chart.add(key, value) # Render chart chart.render_to_file(file_name + '.svg') chart.render_to_png(file_name + '.png') return True
def main(): data = pandas.read_excel("20181214-ridershipData-201811.xls") # print(data["Total Ridership1 "]) passenger = list() for i in data["Total Ridership1 "]: if not str(i).isalpha(): passenger.append(i) # print(passenger) line_chart = pygal.HorizontalLine() line_chart.title = 'You know? Jack is so fat!' # line_chart.x_labels = map(str, range(2002, 2013)) line_chart.add('Jack', passenger) # line_chart.range = [0, 100] line_chart.render_to_file("graph/jack_fat.svg")
step, num_positive_avg_games)) else: print( "Reg Game # %7d avgScore %8.3f last_game_avg %8.3f max_game_avg %8.3f memory size %8d memMax %8.3f steps %5d pos games %5d" % (game, memoryR.mean(), last_game_average, memoryW.max(), memoryR.shape[0], memoryR.max(), step, num_positive_avg_games)) if game % 5 == 0 and np.alen(memoryR) > 1000: mGames.append(game) mSteps.append(step / 1000 * 100) mAPPicks.append(mAP_Counts / step * 100) mAverageScores.append(max(memoryR.mean() * 200, -150)) bar_chart = pygal.HorizontalLine() bar_chart.x_labels = map( str, mGames) # Then create a bar graph object bar_chart.add('Average score', mAverageScores) # Add some values bar_chart.add('percent actor picks ', mAPPicks) # Add some values bar_chart.add('percent steps complete ', mSteps) # Add some values bar_chart.render_to_file(version_name + 'Performance2_bar_chart.svg') break plt.plot(mstats)
# Copyright (C), 2001-2018, yeeku.H.Lee # # # # This program is protected by copyright laws. # # # # Program Name: # # # # <br>Date: # ######################################################################### import pygal x_data = ['2011', '2012', '2013', '2014', '2015', '2016', '2017'] # 构造数据 y_data = [58000, 60200, 63000, 71000, 84000, 90500, 107000] y_data2 = [52000, 54200, 51500, 58300, 56800, 59500, 62700] # 创建pygal.HorizontalLine对象(水平折线图) horizontal_line = pygal.HorizontalLine() # 添加两组代表折线的数据 horizontal_line.add('疯狂Java讲义', y_data) horizontal_line.add('疯狂Android讲义', y_data2) # 设置Y轴(确实如此)的刻度值 horizontal_line.x_labels = x_data # 重新设置X轴(确实如此)的刻度值 horizontal_line.y_labels = [20000, 40000, 60000, 80000, 100000] horizontal_line.title = '疯狂图书的历年销量' # 设置X、Y轴的标题 horizontal_line.x_title = '销量' horizontal_line.y_title = '年份' # 设置将图例放在底部 horizontal_line.legend_at_bottom = True # 指定将数据图输出到SVG文件中 horizontal_line.render_to_file('fk_books.svg')
def pandas_to_pygal_StackedMultiLine(data, groupby1, groupby2, aggregate, absolute_values=True, colourstyle=colour_dict["DefaultStyle"], decimal_places=0, fill=False, print_values=False, horizontal=False, stacked=False, title="Test Grouped Bar Chart", value_suffix="", x_label_rotation=0, cubic=False, legend_at_bottom=False, legend_at_bottom_columns=3, agg_type="sum"): ''' Create pygal object ''' if stacked == True and horizontal == True: pyg = pygal.HorizontalStackedLine() elif horizontal == True and stacked == False: pyg = pygal.HorizontalLine() elif horizontal == False and stacked == True: pyg = pygal.StackedLine() else: pyg = pygal.Line() ''' Transform data for pygal object ''' groupby1_distinct = sorted(data[groupby1].unique()) groupby2_distinct = sorted(data[groupby2].unique()) dict = {} for name in groupby2_distinct: dict[name] = [] for name in groupby2_distinct: for name2 in groupby1_distinct: subset_data = data[(data[groupby1] == name2) & (data[groupby2] == name)] rows_in_subset_data = subset_data.shape[0] aggregate_value = return_aggregate_series(subset_data[aggregate], agg_type) if rows_in_subset_data > 0: dict[name].append(aggregate_value) else: dict[name].append(None) if absolute_values == False: totals = [] dict_values_lists = list(dict.values()) number_of_lists = len(dict_values_lists) number_of_items_per_list = len(dict_values_lists[0]) for index in range(number_of_items_per_list): total = 0 for index2 in range(number_of_lists): current_value = dict_values_lists[index2][index] if current_value is not None: total = total + current_value totals.append(total) percentage_dict = {} for key in dict.keys(): percentage_dict[key] = [] for key in dict.keys(): for index in range(len(dict[key])): numerator = dict[key][index] denominator = totals[index] if numerator is not None and denominator is not None: percentage_dict[key].append(numerator / denominator * 100) else: percentage_dict[key].append(None) ''' Add data to pygal object ''' if absolute_values == True: for key in dict.keys(): pyg.add(key, dict[key]) else: for key in percentage_dict.keys(): pyg.add(key, percentage_dict[key]) ''' Chart configuration options ''' if cubic == True: pyg.config.interpolate = "cubic" pyg.config.legend_at_bottom = legend_at_bottom pyg.config.legend_at_bottom_columns = legend_at_bottom_columns pyg.config.style = colourstyle pyg.config.x_labels = groupby1_distinct pyg.config.fill = fill pyg.config.title = title pyg.config.x_label_rotation = x_label_rotation pyg.config.print_values = print_values formatter = "{:,." + str(decimal_places) + "f} " + str(value_suffix) pyg.config.formatter = lambda x: formatter.format(x) ''' Return chart object ''' return pyg