def render_svg(data_dicts): """Render data to svg.""" names, plot_dicts = [], [] for data_dict in data_dicts: names.append(data_dict['title']) plot_dict = { 'value': data_dict['comments'], 'label': data_dict['title'], 'xlink': data_dict['link'], } plot_dicts.append(plot_dict) # Make visualization. my_style = LS('#333366', base_style=LCS) my_style.title_font_size = 24 my_style.label_font_size = 14 my_style.major_label_font_size = 18 my_config = pygal.Config() my_config.x_label_rotation = 45 my_config.show_legend = False my_config.tuncate_label = 15 my_config.show_y_guides = False my_config.width = 1000 chart = pygal.Bar(my_config, style=my_style) chart.title = 'Most-Active discussion on Hacker News.' chart.x_labels = names chart.add('', plot_dicts) chart.render_to_file('discussion.svg')
def generate_rating_file(lang): url = 'https://api.github.com/search/repositories?q=language:' + str( lang) + '&sort=starts' r = requests.get(url) response_dict = r.json() repo_dicts = response_dict['items'] names, stars = [], [] for repo_dict in repo_dicts: names.append(repo_dict['name']) stars.append(repo_dict['stargazers_count']) my_style = LS('#333366', base_style=DCS) my_style.title_font_size = 24 my_style.label_font_size = 14 my_style.major_label_font_size = 18 my_config = pygal.Config() my_config.x_label_rotation = 45 my_config.show_legend = False my_config.truncate_label = 15 my_config.show_y_guides = False my_config.width = 1000 chart = pygal.Bar(my_config, style=my_style) chart.title = 'Most-Starred ' + str(lang) + ' Projects on GitHub' chart.x_labels = names chart.add(' ', stars) return chart.render_to_file('visualize/static/visualize/repos.svg')
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 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 render_lang_repo(lang): """Render language repo to svg.""" # Make an API call and store the response. url = 'https://api.github.com/search/repositories?q=language:%s&sort=stars' % lang r = requests.get(url) print('Status code:', r.status_code) # Store API response in a variable. response_dict = r.json() print('Total repositories:', response_dict['total_count']) # Explore information about the repositories. repo_dicts = response_dict['items'] names, plot_dicts = [], [] for repo_dict in repo_dicts: names.append(repo_dict['name']) # Get the project description, if one is available. description = repo_dict['description'] if not description: description = 'No description provided.' plot_dict = { 'value': repo_dict['stargazers_count'], 'label': str(description), 'xlink': repo_dict['html_url'], } plot_dicts.append(plot_dict) # Make visualization. my_style = LS('#333366', base_style=LCS) my_style.title_font_size = 24 my_style.label_font_size = 14 my_style.major_label_font_size = 18 my_config = pygal.Config() my_config.x_label_rotation = 45 my_config.show_legend = False my_config.tuncate_label = 15 my_config.show_y_guides = False my_config.width = 1000 chart = pygal.Bar(my_config, style=my_style) chart.title = 'Most-Starred %s Projects on GitHub' % lang.title() chart.x_labels = names chart.add('', plot_dicts) chart.render_to_file('%s_repos.svg' % lang)
def construction_graph(names, plot_dicts): # Построение визуализации. my_style = LS('#333366', base_style=LCS) my_style.title_font_size = 24 my_style.label_font_size = 14 my_style.major_label_font_size = 18 my_config = pygal.Config() my_config.x_label_rotation = 45 my_config.show_legend = False my_config.truncate_label = 15 my_config.show_y_guides = False my_config.width = 1000 chart = pygal.Bar(my_config, style=my_style) chart.title = 'Most-Starred Python Projects on GitHub' chart.x_labels = names chart.add('', plot_dicts) chart.render_to_file('python_repos.svg')
def make_visualization(names, plot_dicts): """Make visualization of most popular repositories.""" my_style = LS('#333366', base_style=LCS) my_style.title_font_size = 24 my_style.label_font_size = 14 my_style.major_label_font_size = 18 my_config = pygal.Config() my_config.x_label_rotation = 45 my_config.show_legend = False my_config.truncate_label = 15 my_config.show_y_guides = False my_config.width = 1000 chart = pygal.Bar(my_config, style=my_style) chart.title = 'Most-Starred Python Projects on GitHub' chart.x_labels = names chart.add('', plot_dicts) chart.render_to_file('python_repos.svg')
def make_visualization(names, plot_dict): """ Make a visualization of data with pygal bar chart. """ my_style = LS('#733380', base_style=LCS) my_style.title_font_size = 24 my_style.label_font_size = 14 my_style.major_label_font_size = 18 my_config = pygal.Config() my_config.value_formatter = lambda y: f'{y:,.0f}' # format (123,456) my_config.x_label_rotation = 45 my_config.show_legend = False my_config.tooltip_fancy_mode = False my_config.truncate_label = 15 my_config.show_y_guides = False my_config.width = 1000 chart = pygal.Bar(my_config, style=my_style) chart.title = 'Most-Starred JavaScript Projects on GitHub' chart.x_labels = names chart.add('', plot_dicts) chart.render_to_file('./working_with_apis/images/svg/javascript_repos.svg')
def make_visualization(name, plot_dicts): """ Visualize most popular repositories with pygal bar chart. """ my_style = LS('#336699', base_style=LCS) my_style.title_font_size = 24 my_style.label_font_size = 14 my_style.major_label_font_size = 18 my_config = pygal.Config() my_config.value_formatter = lambda y: f'{y:,.0f}' # format (123,456) my_config.x_label_rotation = 45 my_config.show_legend = False my_config.tooltip_fancy_mode = False # Hides title from tooltip on hover my_config.truncate_label = 15 my_config.show_y_guides = False my_config.width = 1000 chart = pygal.Bar(my_config, style=my_style) chart.title = 'Most-Starred Python Projects on GitHub' chart.x_labels = names chart.add('', plot_dicts) chart.render_to_file('./working_with_apis/images/svg/python_repos.svg')
plot_dicts.append(plot_dict) ''' print('\nName:', repo_dict['name']) print('Owner:', repo_dict['owner']['login']) print('Stars:', repo_dict['stargazers_count']) print('Repository:', repo_dict['html_url']) print('Created:', repo_dict['created_at']) print('Updated:', repo_dict['updated_at']) print('Description:', repo_dict['description']) ''' ##Make visualization. p_style = LS('#333366', basestyle=LCS) p_style.title_font_size = 24 p_style.label_font_size = 12 p_style.major_label_font_size = 14 p_config = pygal.Config() p_config.x_label_rotation = 45 p_config.show_legend = False p_config.truncate_label = 15 #p_config.show_y_guides = False p_config.width = 1000 chart = pygal.Bar(p_config, style=p_style) chart.title = 'Most-Starred C Project on GitHub' chart.x_labels = names chart.y_labels = [x for x in range(0, 60000, 4000)] #chart.add ('', stars)
names.append(repo_dict["name"]) #stars.append(repo_dict["stargazers_count"]) description = repo_dict["description"] if not description: description = "No description provided." plot_dict = { "value": repo_dict["stargazers_count"], "label": description, "xlink": repo_dict["html_url"] } plot_dicts.append(plot_dict) my_style = LS("#333366", base_style=LCS) my_style.title_font_size = 24 my_style.label_font_size = 14 my_style.major_label_font_size = 18 my_config = pygal.Config() my_config.x_label_rotation = 45 my_config.show_legend = False my_config.truncate_label = 15 my_config.show_y_guides = False my_config.width = 1000 chart = pygal.Bar(my_config, style=my_style) chart.title = "Most-Starred Python Projects on Guthub" chart.x_labels = names chart.add("", plot_dicts) chart.render_to_file("python_repos.svg")
names.append(repoDict['name']) description = repoDict['description'] if not description: description = 'No description found.' plotDict = { 'value': repoDict['stargazers_count'], 'label': description, 'xlink': repoDict['html_url'], } plotDicts.append(plotDict) myStyle = LS('#666633', base_style=LCS) myStyle.title_font_size = 24 myStyle.label_font_size = 14 myStyle.major_font_size = 18 myConfig = pygal.Config() myConfig.x_label_rotation = 45 myConfig.show_legend = False myConfig.truncate_lable = 15 myConfig.show_y_guides = False myConfig.width = 1000 chart = pygal.Bar(myConfig, style=myStyle) chart.title = 'Most starred python projects on Github' chart.x_labels = names chart.add('', plotDicts) chart.render_to_file('python_repos.svg')
# Visualizing the repos with pygal # ----------------------------------------------------------------------------- my_style = LS('#25bec4', base_style=LCS) my_style.title_font_family = 'Helvetica' # NOTE: google fonts will only render when the svg is embedded because the # google stylesheet is added in the XML processing. # my_style.title_font_family = 'googlefont:Slabo' my_style.title_font_size = 14 my_style.foreground = '#586e75' my_style.foreground_strong = '#334145' my_style.foreground_subtle = '#fdca32' my_style.label_font_size = 9 my_style.major_label_font_size = 12 my_style.tooltip_font_size = 11 my_config = pygal.Config() my_config.show_legend = False my_config.truncate_label = 15 my_config.show_y_guides = True my_config.width = 1000 my_config.y_labels = list(range(0, 42000, 2000)) my_config.y_labels_major_count = 3 my_config.x_labels = names my_config.x_label_rotation = 45 chart = pygal.Bar(my_config, style=my_style)
else: solved_ext = int(solved_ext) if solved_ext == 0: solved = solved[:20] notSolved_ext = request.args.get('notSolved_ext') if not notSolved_ext: notSolved_ext = 0 else: notSolved_ext = int(notSolved_ext) if notSolved_ext == 0: notSolved = notSolved[:20] customStyle = LightenStyle('#337ab7') customStyle.background = '#eeeeee' customStyle.label_font_size = 14 customStyle.tooltip_font_size = 25 chart_type = request.args.get('chart_type') if not chart_type: chart_type = 0 else: chart_type = int(chart_type) chart = None if chart_type == 0: chart = pygal.Bar(show_legend=False, style=customStyle, order_min=0) chart.title = 'Problems solved per tag' chart.x_labels = allTags chart.x_label_rotation = 45 chart.show_x_labels = False
#Get the project description, if one is available description = repo_dict['description'] if not description: description = "No description provided." plot_dict = { 'value': repo_dict[ 'stargazers_count'], #value to determine bar height, label to create tooltip for each bar. 'label': description, #label to create tooltip for each bar 'xlink': repo_dict['html_url'] } #add clickable links plot_dicts.append(plot_dict) #Make visualization my_style = LS('#333366', base_style=LCS) my_style.title_font_size = 24 my_style.label_font_size = 14 #labels on x-axis, most numbers on y axis my_style.major_label_font_size = 18 #labels on y-axis mark off 50000 increments; my_config = pygal.Config() #instance of Config class my_config.x_label_rotation = 45 my_config.show_legend = False #Only plot one series on the charts so show_legend=F my_config.truncate_label = 15 #Truncate x label to 15 characters my_config.show_y_guides = False #hide horizontal lines on the graph my_config.width = 1000 #custome bar width chart = pygal.Bar(my_config, style=my_style) chart.title = 'Most-starred Python Projects on GitHub' chart.x_labels = names chart.add( '', plot_dicts
for repo_dict in repo_dicts: names.append(repo_dict['name']) plot_dict = { 'value': repo_dict['stargazers_count'], 'label': str(repo_dict['description'])[:150] + "...", 'xlink': repo_dict['html_url'] } plot_dicts.append(plot_dict) # Visualization my_style = LightenStyle('#333366', base_style=LightColorizedStyle) # font_size is now in class Style not class Config my_style.title_font_size = 24 # default 16 my_style.label_font_size = 14 # default 10 my_style.major_label_font_size = 18 # default 10 my_config = pygal.Config() my_config.x_label_rotation = 45 my_config.show_legend = False my_config.truncate_label = 15 my_config.show_y_guides = False my_config.width = 1000 chart = pygal.Bar(my_config, style=my_style) chart.title = "Most-Starred Python Projects on Github" chart.x_labels = names chart.add('', plot_dicts) chart.render_to_file('python_repos.svg')