def investigate_top_tweets(graph): trimmed_graph = f.trim_graph(graph, 'weight', 50000, key='type', value='hashtags') trimmed_graph = f.trim_graph(trimmed_graph, 'weight', 500, key='type', value='user') degrees = trimmed_graph.degree() for node in degrees.keys(): if degrees[node] < 1: trimmed_graph.remove_node(node) print len(trimmed_graph.nodes()) #Normalize the weights for better drawing, now that it's trimmed: total_weights={'user':0, 'hashtag':1} for node in trimmed_graph.nodes(): total_weights[trimmed_graph.node[node]['type']]+=trimmed_graph.node[node]['weight'] for node in trimmed_graph.nodes(): type=trimmed_graph.node[node]['type'] total = float(total_weights[type]) trimmed_graph.node[node]['normalized_weight'] = trimmed_graph.node[node]['weight'] / total if type is 'user': trimmed_graph.node[node]['normalized_weight'] *= 10000 #Scale for viewing else: trimmed_graph.node[node]['normalized_weight'] *= 1000 f.write_network_gml(trimmed_graph, 'trimmed-user-tags-hi_threshold')
plt.title('Number of Triangles vs. Clustering Coefficient') plt.ylabel("Triangles") plt.xlabel("Clustering Coefficient") plt.xlim([0,.06]) plt.ylim([0,60]) return plt ############################## RUNTIME ####################################### if __name__ == '__main__': # Get all retweets retweets = bf.query_mongo_get_list(bf.retweets) print "Number of Retweets: ", len(retweets) retweets_graph = retweeted_graph(retweets) print "Nodes: ", len(retweets_graph.nodes()), "Edges: ", len(retweets_graph.edges()) # Trim nodes to greater than 500 trimmed_retweets = f.trim_graph(retweets_graph,'weight', 500) print "Trimmed to 500:",len(trimmed_retweets.nodes()) #f.write_network_gml(trimmed_retweets,'retweeted_hashtags_gt_500') # Triangles Vs. Clustering Coefficient make_triangle_cc_plot(trimmed_retweets, show_labels=True, threshold=60).show() # Centralities: #f.print_betweenness_centrality(trimmed_retweets) # f.write_network_gml(pruned_graph, 'retweets_hashtag_gt800_real_degree') #f.draw_network_plt(pruned_graph, scale=(.1)) #For quick visualization