import numpy as np from word_cloud.wordcloud import make_wordcloud from config import ( WIDTH, HEIGHT, CLOUD_IMAGE_FILENAME) # get word counts count = {} with open('names.txt') as f: for line in f: username = line[:-1] count[username.decode('utf8')] = count.get(username, 0) + 1 words = np.array(count.keys()) counts = np.array(count.values()) make_wordcloud( words, counts, CLOUD_IMAGE_FILENAME, width=WIDTH, height=HEIGHT, font_path="OldSansBlack.ttf", redraw_in_color=False)
sw.add('-') sw.add('&') sw.add('RT') sw.add("it's") counts_and_words = [] for line in open(args.json_file): word, count = json.loads(line) #print word, count counts_and_words.append((count, word)) counts_and_words.sort() counts_and_words.reverse() words = [] counts = [] for count, word in counts_and_words: if word.lower() not in sw: print word, count words.append(word) counts.append(count) if len(words) == 200: break words = np.array(words) counts = np.array(counts) output_filename = "output.png" font_path = "/usr/share/fonts/truetype/droid/DroidSansMono.ttf" wordcloud.make_wordcloud(words, counts, output_filename, font_path, width=800, height=600)
import numpy as np from word_cloud.wordcloud import make_wordcloud from config import (WIDTH, HEIGHT, CLOUD_IMAGE_FILENAME) # get word counts count = {} with open('names.txt') as f: for line in f: username = line[:-1] count[username.decode('utf8')] = count.get(username, 0) + 1 words = np.array(count.keys()) counts = np.array(count.values()) make_wordcloud(words, counts, CLOUD_IMAGE_FILENAME, width=WIDTH, height=HEIGHT, font_path="OldSansBlack.ttf", redraw_in_color=False)
counts_and_words = [] for line in open(args.json_file): word, count = json.loads(line) #print word, count counts_and_words.append((count, word)) counts_and_words.sort() counts_and_words.reverse() words = [] counts = [] for count, word in counts_and_words: if word.lower() not in sw: print word, count words.append(word) counts.append(count) if len(words) == 200: break words = np.array(words) counts = np.array(counts) output_filename = "output.png" font_path = "/usr/share/fonts/truetype/droid/DroidSansMono.ttf" wordcloud.make_wordcloud(words, counts, output_filename, font_path, width=800, height=600)