def draw_radar(semep, metis, percentile, dirname): title = "Percentile " + percentile custom_style = Style( background='transparent', plot_background='transparent', #foreground='#53E89B', #foreground_strong='#53A0E8', #foreground_subtle='#630C0D', #opacity='.6', #opacity_hover='.9', transition='400ms ease-in', #colors=('#0093AF','#FFAE64') colors=('#FF7C00', '#006C80')) radar_chart = pygal.Radar(style=custom_style, height=400) radar_chart.fill = True radar_chart.title = title radar_chart.x_labels = [ 'Inv. Conductance', 'Coverage', 'Norm. Modularity', 'Inv. Norm. Total Cut', 'Performance' ] radar_chart.add('Korona_SemEP', [ semep.conductance, semep.coverage, semep.modularity, semep.total_cut, semep.performance ]) radar_chart.add('Korona_Metis', [ metis.conductance, metis.coverage, metis.modularity, metis.total_cut, metis.performance ]) radar_chart.render() filename = "radar_chart_" + percentile + ".svg" radar_chart.render_to_file(join(dirname, filename))
def playlist_mood_graph(key): if key == API_KEY: value = request.args.get('playlist') playlist = playlist_str_to_ls(value) mood_dict = mood() recs = mood_playlist_recs(playlist) li = [i['id'] for i in recs] features = get_all_features(li) spotify = auth() custom_style = fixed_style radar_chart = pygal.Radar(style=custom_style) radar_chart.x_labels = list(features.drop('id', axis=1).keys()) for id, feature_vec in zip(features.id, features.drop('id', axis=1).values): radar_chart.add( spotify.track(id)['name'], spot_scaler.transform([feature_vec])[0]) graph_data = radar_chart.render_data_uri() return render_template('radar.html', graph_data=graph_data, title='Song Feature Graph')
def playlist_recs(key): if key == API_KEY: value = request.args.get('playlist') spotify = auth() playlist = playlist_str_to_ls(value) recs = rec_data(playlist) li = [i['id'] for i in recs] features = get_all_features(li) feats = default_mood(playlist) custom_style = fixed_style radar_chart = pygal.Radar(style=custom_style) radar_chart.x_labels = list(features.drop('id', axis=1).keys()) for id, feature_vec in zip(features.id, features.drop('id', axis=1).values): radar_chart.add( spotify.track(id)['name'], spot_scaler.transform([feature_vec])[0]) graph_data = radar_chart.render_data_uri() graph_dict = [{'graph_uri': graph_data}, feats, recs] return jsonify(graph_dict)
def make_radar_chart(title, data_title, data, data_title2=None, data2=None): """ Input: title: string data_title: string data: dictionary whereby the keys will be the x-axis and the values the data to be plotted ... Output: returns a radar chart to the browser """ # make the chart # radar_chart = pygal.Radar(fill=True, style=LightSolarizedStyle, range=(0, 10)) radar_chart = pygal.Radar(fill=True, range=(0, 10), show_dots=False) # add the title radar_chart.title = title # add the x-axis values radar_chart.x_labels = [item for item in data] # add the data radar_chart.add(data_title, [data[item] for item in data]) if data2: radar_chart.x_labels = [item for item in data2] radar_chart.add(data_title2, [data2[item] for item in data2]) #return the radar chart radar_chart.render_in_browser()
def graph_data(key, value): if key == API_KEY: spotify = auth() recs = top_recs([value]) features = pd.concat([get_all_features([value]), recs]) feat_dict = songs_data(features) custom_style = fixed_style radar_chart = pygal.Radar(style=custom_style) radar_chart.title = ('Comparison of Recommendations for \"' + spotify.track(value)['name'] + '\"') radar_chart.x_labels = list(features.drop('id', axis=1).keys()) for id, feature_vec in zip(features.id, features.drop('id', axis=1).values): radar_chart.add( spotify.track(id)['name'], spot_scaler.transform([feature_vec])[0]) graph_data = radar_chart.render_data_uri() graph_dict = [{'graph_uri': graph_data}, feat_dict] return jsonify(graph_dict)
def mvp_radar_graph(total_stats_df): """Returns a radar graph for the MVP (person with the most total points). The radar graph breaks down their points by batting, bowling, fielding and bonus param total_stats_df The dataframe containing the data needed (in this case we will have total_stats_df = get_sheet_df('TotalStats')""" # Discard unecessary columns so we're left with Player Name, Player Role and their points in each category (and total points) total_stats = total_stats_df.drop([ 'Player Number', 'GAMES', 'RUNS', '4s', '6s', '50s', '100s', '150s', '200s', 'DUCKS', 'OVERS', 'BALLS', 'WICKETS', 'RUNS AGAINST', 'MAIDENS', '3fers/4fers', '5fers', '6+fers', 'CATCHES', 'RUN-OUTS', 'STUMPINGS', 'MOTM', 'WINS' ], axis=1) # Sort data in decreasing order of total points and get the person with highest total points total_stats.sort_values(by=['TOTAL'], ascending=False, inplace=True) mvp_stats = list(total_stats.iloc[0]) # Generate the radar chart mvp_name = mvp_stats[0] radar_chart = pygal.Radar(style=style, show_legend=False) radar_chart.title = f"MVP {mvp_name}'s points by category." radar_chart.x_labels = [ 'Batting Points', 'Bowling Points', 'Fielding Points', 'Bonus Points' ] radar_chart.add(mvp_name, mvp_stats[2:6]) # Render the radar chart radar_graph_data = radar_chart.render_data_uri() return radar_graph_data
def cluster_overview_radar(cls, clusters, filename=None): chart = pygal.Radar(fill=True, style=BlueStyle( font_family='googlefont:Source Sans Pro', value_font_size=30, label_font_size=30, value_label_font_size=30, title_font_size=30, major_label_font_size=30, tooltip_font_size=30, legend_font_size=30, no_data_font_size=30), ) chart.title = 'Comet Virtual Cluster Radar for Status of the Nodes' chart.x_labels = ['pending', 'active', 'unkown', 'down', 'total'] for cluster in clusters: state = cluster['status'] data = [state["active"], state["down"], state['pending'], cluster['total']] chart.add(cluster['name'], data) if filename is not None: chart.render_to_file(cls.to_path(filename)) return chart
def graph(): _charts = [ pygal.Line(), pygal.Bar(), pygal.Histogram(), pygal.XY(), pygal.Pie(), pygal.Radar(), pygal.Box(), pygal.Dot(), pygal.Funnel(), pygal.SolidGauge(), pygal.Gauge(), pygal.Pyramid(), pygal.Treemap() ] charts = [] for chart in _charts: chart.title = '% Change Coolness of programming languages over time.' chart.x_labels = ['2011', '2012', '2013', '2014', '2015', '2016'] chart.add('Python', [15, 31, 89, 200, 356, 900]) chart.add('Java', [15, 45, 76, 80, 91, 95]) chart.add('C++', [5, 51, 54, 102, 150, 201]) chart.add('All others combined!', [5, 15, 21, 55, 92, 105]) charts.append(chart.render_data_uri()) return render_template('part2/graph.html', charts=charts, root_path=root_path)
def player_network_skills(p_name): retorno = [] ataque = 0 violencia = 0 regularidade = 0 performance = 0 a = select([ stats_table.c.s_matches_played, stats_table.c.s_gols, stats_table.c.s_yellow_card, stats_table.c.s_red_card, stats_table.c.s_substituido ]).where(and_(stats_table.c.s_name == p_name, )) for row in a.execute(): retorno.append(row) for i, val in enumerate(retorno): regularidade = regularidade + retorno[i][0] ataque = ataque + retorno[i][1] violencia = violencia + retorno[i][2] + retorno[i][3] performance = performance + retorno[i][4] radar_chart = pygal.Radar(style=custom_style) radar_chart.x_labels = [ 'Ataque', 'Violência', 'Regularidade', 'Performance' ] radar_chart.add('Performance', [ataque, violencia, (regularidade / 30), performance]) return radar_chart
def get_image(self): custom_style = Style( background='#ffffff', plot_background='#ffffff', # foreground='#53E89B', # foreground_strong='#53A0E8', # foreground_subtle='#630C0D', # opacity='.6', # opacity_hover='.9', # transition='400ms ease-in', colors=('rgb(255, 0, 0)', 'rgb(18, 5, 240)', 'rgb(255, 153, 0)', 'rgb(16, 150, 24)')) radar_chart = pygal.Radar(legend_at_bottom=True, width=450, height=450, style=custom_style, show_legend=False) radar_chart.title = self.get_options()['title'] radar_chart.x_labels = self.get_xlabels() for i in self.get_options()['col-included']: radar_chart.add(i['name'], self.get_opt_data(i['col-no']), fill=i['fill'], show_dots=False, stroke_style={ 'width': 3, 'linecap': 'round', 'linejoin': 'round' }) # radar_chart.add('Dead', self.get_opt_data(2), fill=True, show_dots=False) # radar_chart.add('Violent', self.get_opt_data(3), fill=True, show_dots=False) # radar_chart.add('Injured', self.get_opt_data(4), fill=False, show_dots=False) return radar_chart.render_data_uri(human_readable=True)
def make_chart(username, style='default', **args): if isinstance(style, list): style = style[0] style = pygal.style.styles[style] chart = pygal.Radar(style=style, fill=True) chart = add_to_chart(chart, username) return chart
def plotGame(self): # 用于绘图 # data用于保存每一把枪的性能数据 data = [] num = 0 # 枪的性能 for ii in self.res2: if num < 7: num += 1 ii = "https://pubgm.qq.com" + ii a = requests.get(ii).text self.res1 = re.compile(r'<span style="width:(.*?)%;"></span>') self.reg1 = re.findall(self.res1, a) data.append([ int(self.reg1[0]), int(self.reg1[1]), int(self.reg1[2]), int(self.reg1[3]) ]) # 调用Rader类,并设置雷达图的填充(fill=True),及数据范围(range(0,100)) radar_chart = pygal.Radar() radar_chart.title = '步枪性能' radar_chart.x_labels = ['射速', '威力', '射程', '稳点'] for ff, property in zip(self.name, data): print(ff, property) # 绘制雷达图区域 radar_chart.add(ff, property) # 保存图像 radar_chart.render_to_file('步枪性能图.svg')
def __init__(self, **kwargs): self.data = {} self.chart = pygal.Radar(**kwargs) self.chart.style = DefaultStyle(tooltip_font_size=14) self.chart.legend_at_bottom = True self.chart.legend_at_bottom_columns = 3
def start_radar(videos_info, user, CategoryYoutube): from pygal.style import Style custom_style = Style(background='black', plot_background='black', foreground='#53E89B', foreground_strong='#53A0E8', foreground_subtle='#630C0D', opacity='.6', opacity_hover='.9', label_font_size=7, transition='400ms ease-in', colors=('#E853A0', '#E8537A', '#E95355', '#E87653', '#E89B53')) #from test_area import CategoryYoutube label = labeling(CategoryYoutube) # Category=IdCategory,nameCategory normalized1 = compact_data(videos_info, CategoryYoutube) # normalized2=compact_data(fr1) # fr=Counter(i[3] for i in a) radar_chart = pygal.Radar(show_legend=True, fill=True, style=custom_style) radar_chart.x_labels = label radar_chart.add('user1', normalized1) # radar_chart.add('user2', normalized2) radar_chart.render_to_file(user + '.svg') return 1
def __init__(self, **kwargs): self.chart = pygal.Radar(height=400, width=400, style=BlueStyle( font_family='googlefont:Roboto', value_colors=('black', )), show_legend=False, fill=True)
def radar_chart(): """Need set number of axis, and each data should has same number of values.""" line = 6 radar = pygal.Radar() radar.title = 'RADAR CHART TEST' radar.x_labels = ['TAR {}'.format(x) for x in range(line)] for i in range(3): radar.add('Item {}'.format(i), get_random_data(line)) radar.render_to_file(get_file_name(inspect.stack()[0][3]))
def create_radar_chart(): radar_chart = pygal.Radar() radar_chart.title = 'V8 benchmark results' radar_chart.x_labels = ['Richards', 'DeltaBlue', 'Crypto', 'RayTrace', 'EarleyBoyer', 'RegExp', 'Splay', 'NavierStokes'] radar_chart.add('Chrome', [6395, 8212, 7520, 7218, 12464, 1660, 2123, 8607]) radar_chart.add('Firefox', [7473, 8099, 11700, 2651, 6361, 1044, 3797, 9450]) radar_chart.add('Opera', [3472, 2933, 4203, 5229, 5810, 1828, 9013, 4669]) radar_chart.add('IE', [43, 41, 59, 79, 144, 136, 34, 102]) radar_chart.render_in_browser()
def Radar_Chart(self): radar_chart = pygal.Radar(fill=True, range=(0, 100)) radar_chart.title = self.name + ' Grading' radar_chart.x_labels = [ 'Price', 'Environment', 'Location', 'Service', 'Others' ] radar_chart.add(self.name, [ self.P_grade, self.E_grade, self.L_grade, self.S_grade, self.O_grade ])
def display_radar(self, data_dict): title_builder = [] title = "" radar_chart = pygal.Radar() for key, data_list in data_dict.items(): title_builder.append(key + ' vs ') title = ''.join(title_builder) radar_chart.add(key, data_list) radar_chart.title = title[:-4] radar_chart.render_in_browser()
def drawRadar_pygal(title, case_data, path, showPlot): title = title[0:1] + title[-1:0:-1] case_data = case_data[0:1] + case_data[-1:0:-1] dark_lighten_style = LightenStyle(theme_color, step=5, max_=10) dark_lighten_style1 = LightenStyle('#ff0000') colorset = ['#cfefdf', '#a7e1c4', '#76d0a3'] dark_lighten_style.opacity = 0.5 dark_lighten_style.background = '#ffffff' 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 dark_lighten_style.legend_font_size = 40 dark_lighten_style.colors = [colorset[1], theme_color] # dark_lighten_style.foreground = 'rgba(0, 0, 0, .87)' # raise radar_chart = pygal.Radar(show_legend=True, width=1600, height=1200, style=dark_lighten_style, margin=25, spacing=20, stroke_style={'width': 5}, dots_size=8, show_dots=1, stroke=1) # radar_chart.title = 'V8 benchmark results' radar_chart.x_labels = title if max(case_data) < 1: case_data = [c * 100 for c in case_data] # radar_chart.add('Chrome1', [{'value':50,'style': 'fill: False; stroke: red; stroke-width: 4;stroke-dasharray: 15, 10, 5, 10, 15'}]*len(case_data)) radar_chart.add('Standard score', [50] * len(case_data), fill=True, show_dots=0, stroke_style={ 'width': 2, 'dasharray': '3, 6' }) radar_chart.add('Your score', case_data) # radar_chart._fill('red') radar_chart.y_labels = [0, 50, 100] # radar_chart.render_to_file('plot/Radar_pygal.svg',fill = True) radar_chart.render_to_png(path + 'Radar_pygal.png', fill=True) if showPlot: display({'image/svg+xml': radar_chart.render(fill=True)}, raw=True)
def make_radar(lex_cats): '''Takes a list of lists e.g. [['fruit',0.02],['science',0.01]] Creates an svg file called lexical_radar.svg''' radar_chart = pygal.Radar() radar_chart.title = 'Top 8 Lexical Categories by Proportion of Total Words' lex_cats.sort(key=lambda x: x[1], reverse=True) top_eight = lex_cats[:8] radar_chart.x_labels = [cat[0] for cat in top_eight[::-1]] radar_chart.add('Your Sample', [cat[1] for cat in top_eight[::-1]]) radar_chart.render_to_file('./kojak_flask/static/lexical_radar.svg', fill=True) return True
def radar(): if request.method == 'POST': courseNumber = request.form.get('courseNumber', None) departmentName = request.form.get('departmentName', None) email = request.cookies.get('username') assignmentNames, assignmentGrades = getStudentGrades(email, courseNumber, departmentName) averageGrades = getAverageGrades(assignmentNames, courseNumber, departmentName) radar_chart = pygal.Radar(range=(0, 100)) radar_chart.title = 'Grades' radar_chart.x_labels = assignmentNames radar_chart.add(email, assignmentGrades) radar_chart.add('averages', averageGrades) return Response(response=radar_chart.render(), content_type='image/svg+xml')
def plot_radar_chart(self, adjuster): data_adjuster_mean = self.topsis_analyzer.adjuster_df.loc[adjuster, :] data_mean = self.topsis_analyzer.adjuster_df.mean() radar_chart = pygal.Radar(fill=True) radar_chart.title = adjuster + ' Radar Chart' radar_chart.x_labels = list(self.topsis_analyzer.adjuster_df.columns) radar_chart.add(adjuster, list(np.round(100 * data_adjuster_mean.values, 2))) radar_chart.add('Mean', list(np.round(100 * data_mean.values, 2))) radar_chart.render_to_file(self.directory + '\\' + adjuster + '.svg')
def time_to_post(data): post_data = data['likes'] total_posts_n = len(post_data) posts_in_hour = post_data.groupby(post_data.time.dt.hour) posts_in_hour = dict(posts_in_hour.count().time) index = range(24) values = [(posts_in_hour[i] / total_posts_n) * 100 if i in posts_in_hour else 0 for i in index] radar_chart = pygal.Radar(style=style, show_legend=False, fill=True, height=800) radar_chart.x_labels = index radar_chart.add('', values) return radar_chart
def create_figure_player_performance(self, player1, player2): radar_chart = pygal.Radar(fill=True, style=DefaultStyle) radar_chart.title = 'Player Performance' radar_chart.x_labels = ['Batting', 'Bowling', 'Fielding'] radar_chart.y_labels = [0,20,40,60,80,100] radar_chart.add(player1, [\ self.get_player_batting_rating(player1),\ self.get_player_bowling_rating(player1),\ self.get_player_fielding_rating(player1)]) radar_chart.add(player2, [\ self.get_player_batting_rating(player2),\ self.get_player_bowling_rating(player2),\ self.get_player_fielding_rating(player2)]) return radar_chart.render_data_uri()
def make_radar(datadic,name): # 实例化Radar这个类,fill代表是否填充,range代表每个属性的值范围 radar_chart = pygal.Radar(fill='True',range=(0,100)) # 创建雷达图的标题 radar_chart.title = '武器属性' # 创建雷达图的属性 radar_chart.x_labels = ['威力','射程','射速','稳定性','子弹数'] t = [] # 遍历每个属性字典中的值,并追加到t列表中 for i in datadic: t.append(int(datadic[i])) # 添加武器的属性值和武器名到雷达图中 radar_chart.add(name,t) # 最后命名雷达图的文件 radar_chart.render_to_file('radar(枪支性能).svg')
def TweetCharts(): tweets = [None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None] for x in range(24): num=Tweet.query.filter(extract('hour', Tweet.date_posted)==x).count() tweets[x]=num radar_chart = pygal.Radar(show_legend=False, show_minor_y_labels=False, fill=True, style=custom_style) radar_chart.title = 'Post Time' radar_chart.x_labels = range(0,24) radar_chart.render_data_uri() radar_chart.add('Tweet By Hour',tweets) graphdata = radar_chart.render_data_uri() return graphdata
def test_3(): import pygal # 调用Radar这个类,并设置雷达图的填充,及数据范围 radar_chart = pygal.Radar(fill=True, range=(0, 5)) # 添加雷达图的标题 radar_chart.title = '活动前后员工状态表现' # 添加雷达图各顶点的含义 radar_chart.x_labels = ['个人能力','QC知识','解决问题能力','服务质量意识','团队精神'] # 绘制两条雷达图区域 radar_chart.add('活动前', [3.2, 2.1, 3.5, 2.8, 3]) radar_chart.add('活动后', [4, 4.1, 4.5, 4, 4.1]) # 保存图像 radar_chart.render_to_file('C:\\Users\\zhaozehui\\PycharmProjects\\DataAnalysis\\venv\\data\\radar_chart.png') return
def champ_player_per_position(): #CUSTOMIZAÇÃO DA COR DO GRÁFICO DE SCORE POR ÁREA custom_style = Style( background='transparent', plot_background='#FFF', foreground='#676767', value_font_size = 20.0, label_font_size=20.0, legend_font_size=20.0, major_label_font_size=20.0, guide_stroke_dasharray='#fbfbfb', major_guide_stroke_dasharray='#fbfbfb', foreground_strong='#676767', foreground_subtle='#676767', opacity='.8', opacity_hover='.9', transition='200ms ease-in', colors=('#A09E52', '#78774C', '#68661B', '#4D6219', '#657148', '#82974D', '#7C3F67', '#5D3B51')) retorno = [] goleiros = 0 defensores = 0 meias = 0 atacantes = 0 a = select([players_table.c.p_position]) for row in a.execute(): retorno.append(row) for i, val in enumerate(retorno): if retorno[i][0] == "Goalkeeper": goleiros = goleiros + 1 elif retorno[i][0] == "Defender": defensores = defensores + 1 elif retorno[i][0] == "Midfielder": meias = meias + 1 elif retorno[i][0] == "Attacker": atacantes = atacantes + 1 radar_chart = pygal.Radar(style=custom_style) radar_chart.x_labels = ['Goalkeeper', 'Defender', 'Midfielder', 'Attacker'] radar_chart.add('Brasileirão 2018', [goleiros, defensores, meias, atacantes]) return radar_chart
def main(): data = xlrd.open_workbook('heros.xlsx') table = data.sheets()[0] radar_chart = pygal.Radar() radar_chart.title = "英雄能力值" # print(table.ncols) for i in range(table.nrows): if i == 0: title = table.row_values(i) radar_chart.x_labels = title[1:] print(title) else: data = table.row_values(i) radar_chart.add(data[0], data[1:]) print(data) radar_chart.render_to_file('heros.html')