def plot_centre_dist(self, thresh=2, show_threads=True, **kwargs): """Plots time elapsed since last comment for each participant""" project, show, _ = ac.handle_kwargs(**kwargs) data_high, data_low = self.__get_centre_distances( thresh, split=True) # set up and create plots plt.style.use(SETTINGS['style']) _, axes = plt.subplots() colors_high = ac.color_list( self.author_frame.loc[data_high.columns, 'color'], SETTINGS['vmin'], SETTINGS['vmax'], cmap=CMAP) colors_low = ac.color_list( self.author_frame.loc[data_low.columns, 'color'], SETTINGS['vmin'], SETTINGS['vmax'], cmap=CMAP) data_high.plot(ax=axes, color=colors_high, legend=False) data_low.plot(ax=axes, alpha=.1, color=colors_low, legend=False) axes.set_ylabel("Days elapsed since last comment") axes.set_title("Distance from centre of discussion\n{}".format( project)) axes.xaxis.set_ticks_position('bottom') axes.yaxis.set_ticks_position('left') if show_threads: self.__show_threads(axes) ac.show_or_save(show)
def plot_centrality_measures(self, g_type="interaction", measures=None, delete_on=None, thresh=0, **kwargs): """Shows plot of degree_centrality for each author (only if first measure is non-zero)""" project, show, fontsize = ac.handle_kwargs(**kwargs) if not measures: measures = self.centr_measures centr_cols, centrality, means = self.__get_centrality_measures( g_type, measures) if delete_on is not None: centrality = centrality[centrality[centr_cols[delete_on]] > thresh] colors = ac.color_list(len(measures), SETTINGS['vmin'], SETTINGS['vmax'], factor=15) full_measure_names = centrality.columns centrality.columns = [ col.replace(g_type + " ", "") for col in centrality.columns] plt.style.use(SETTINGS['style']) axes = centrality.plot( kind='bar', color=colors, title="Centrality-measures for {} ({}-graph)".format( project, g_type).title()) for measure, color in zip(full_measure_names, colors): the_mean = means[measure] axes.lines.append( mlines.Line2D( [-.5, len(centrality.index) - .5], [the_mean, the_mean], linestyle='-', linewidth=.5, color=color, zorder=1, transform=axes.transData)) axes.set_xticklabels(centrality.index, fontsize=fontsize) ac.show_or_save(show)
def plot_author_activity_pie(self, what='total comments', **kwargs): """Shows plot of commenting activity as piechart what can be either 'total comments' (default) or 'word counts'""" project, show, fontsize = ac.handle_kwargs(**kwargs) if what not in set(['total comments', 'word counts']): raise ValueError comments = self.author_frame[[what, 'color']].sort_values( what, ascending=False) thresh = int(np.ceil(comments[what].sum() / 100)) whatcounted = 'comments' if what == 'total comments' else 'words' comments.index = [[x if y >= thresh else "fewer than {} {}" .format(thresh, whatcounted) for (x, y) in comments[what].items()]] merged_commenters = comments.index.value_counts()[0] comments = DataFrame({ 'totals': comments[what].groupby(comments.index).sum(), 'maxs': comments[what].groupby(comments.index).max(), 'color': comments['color'].groupby( comments.index).max()}).sort_values( 'maxs', ascending=False) for_pie = comments['totals'] for_pie.name = "" colors = ac.color_list(comments['color'], SETTINGS['vmin'], SETTINGS['vmax'], cmap=CMAP) plt.style.use(SETTINGS['style']) title = "Activity per author for {}".format(project).title() if what == "total comments": title += ' ({} comments, {} with fewer than {} comments)'.format( int(comments['totals'].sum()), merged_commenters, thresh) else: title += ' ({} words, {} with fewer than {} words)'.format( int(comments['totals'].sum()), merged_commenters, thresh) for_pie.plot( kind='pie', autopct='%.2f %%', figsize=(6, 6), labels=for_pie.index, colors=colors, title=('\n'.join(wrap(title, 60))), fontsize=fontsize) ac.show_or_save(show)