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 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 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')
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) # Make Visualization. my_style = LS('#333366', base_style=LCS) my_style.title_font_size = 24 my_style.laber_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')
#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") print("Finish")
names.append(item['name']) if item['description']: description = item['description'] else: description = "No description provided." plots.append({ 'value': item['stargazers_count'], 'label': description, 'xlink': item['html_url'], }) # Make visualization chart_style = LightenStyle('#333366', base_style=LightColorizedStyle) chart_style.title_font_size = 18 chart_style.label_font_size = 12 chart_style.major_label_font_size = 14 chart_config = pygal.Config() chart_config.x_label_rotation = 45 chart_config.show_legend = False chart_config.truncate_label = 15 chart_config.show_y_guides = False chart_config.width = 1000 chart = pygal.Bar(chart_config, style=chart_style) chart.title = "Most-Starred Python Projects on GitHub" chart.x_labels = names chart.add("", plots) chart.render_to_file('python_repos.svg') print("Chart saved as python_repos.svg")
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 ) #height of the bar. Don't need to be labeled, so pass an empty string
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')