def make_visualization(names,plot_dicts): """可视化""" my_style = LS("#333366",base_style = LCS) my_style.title_font_size = 24 my_style.lable_font_size = 14 my_style.major_lable_font_size = 18 my_config = pygal.Config() my_config.x_label_rotation = 45#让标签绕x轴旋转45度(x_label_rotation=45 ) my_config.show_legend = False#隐藏图例(show_legend=False ) my_config.truncate_label = 15#将较长的项目名缩短为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('refactor_python_repos.svg')
print("Comments:", submission_dict['comments']) titles, plot_dicts = [], [] for submission_dict in submission_dicts: titles.append(submission_dict['title']) plot_dict = { 'value': submission_dict['comments'], 'label': submission_dict['title'], 'xlink': submission_dict['link'], } 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_lable_font_size = 18 my_config = pygal.Config() my_config.x_label_rotation = 45 my_config.show_lenged = False my_config.truncate_label = 15 #将较长的项目名缩短为15个字符 my_config.show_y_guides = False #隐藏图表中的水平线 my_config.width = 1000 my_config.y_title = 'Number of Comments' chart = pygal.Bar(my_config, style=my_style) chart.title = 'Most Active Discussions on Hacker News' chart.x_labels = titles chart.add('', plot_dicts) chart.render_to_file('hn_discussions.svg')