Python wordcloud.STOPWORDS Examples
The following are 9
code examples of wordcloud.STOPWORDS().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
wordcloud
, or try the search function
.
Example #1
Source File: analysis.py From dl-eeg-review with MIT License | 8 votes |
def generate_wordcloud(df, save_cfg=cfg.saving_config): brain_mask = np.array(Image.open("./img/brain_stencil.png")) def transform_format(val): if val == 0: return 255 else: return val text = (df['Title']).to_string() stopwords = set(STOPWORDS) stopwords.add("using") stopwords.add("based") wc = WordCloud( background_color="white", max_words=2000, max_font_size=50, mask=brain_mask, stopwords=stopwords, contour_width=1, contour_color='steelblue') wc.generate(text) # store to file if save_cfg is not None: fname = os.path.join(save_cfg['savepath'], 'DL-EEG_WordCloud') wc.to_file(fname + '.' + save_cfg['format']) #, **save_cfg)
Example #2
Source File: QQZoneAnalysis.py From QQZoneMood with MIT License | 5 votes |
def drawWordCloud(self, word_text, filename, dict_type=False, background_image='image/tom2.jpeg'): """ :param word_text: :param filename: :param dict_type: :param background_image: 词云图的背景形状 :return: """ mask = Image.open(BASE_DIR + background_image) mask = np.array(mask) my_wordcloud = WordCloud( background_color='white', # 设置背景颜色 mask=mask, # 设置背景图片 max_words=2000, # 设置最大现实的字数 stopwords=STOPWORDS, # 设置停用词 font_path=self.system_font, # 设置字体格式,如不设置显示不了中文 max_font_size=50, # 设置字体最大值 random_state=30, # 设置有多少种随机生成状态,即有多少种配色方案 scale=1.3 ) if not dict_type: my_wordcloud = my_wordcloud.generate(word_text) else: my_wordcloud = my_wordcloud.fit_words(word_text) image_colors = ImageColorGenerator(mask) my_wordcloud.recolor(color_func=image_colors) # 以下代码显示图片 plt.imshow(my_wordcloud) plt.axis("off") # 保存图片 if not self.from_web: my_wordcloud.to_file(filename=self.image_path + filename + '.jpg') print("result file path:", self.image_path + filename + '.jpg') plt.show() else: my_wordcloud.to_file(filename=self.web_image_bash_path + filename + '.jpg') print("result file path:", self.web_image_bash_path + filename + '.jpg')
Example #3
Source File: 歌词_6词云.py From AI_Poet_Totoro with MIT License | 5 votes |
def show(file, pic): global main_dir d = path.dirname(__file__) text = open(path.join(d, main_dir+file), encoding='utf-8').read() # 自定义图片 my_coloring = np.array(Image.open(path.join(d, pic))) # 设置停用词 stopwords = set(STOPWORDS) stopwords.add("") # 设置词云形状 wc = WordCloud(font_path='simhei.ttf', width=800, height= 600, background_color="white", max_words=300, mask=my_coloring, stopwords=stopwords, max_font_size=110, random_state=200) # 运行统计 wc.generate(text) # 获取color image_colors = ImageColorGenerator(my_coloring) # 展示 plt.imshow(wc, interpolation="bilinear") plt.axis("off") plt.figure() wc.to_file(file+'_1.png') # 按照给定的图片颜色布局生成字体颜色 plt.imshow(wc.recolor(color_func=image_colors), interpolation="bilinear") plt.axis("off") plt.figure() wc.to_file(file+'_2.png') plt.imshow(my_coloring, cmap=plt.cm.gray, interpolation="bilinear") plt.axis("off") plt.show()
Example #4
Source File: wc.py From xi-iot with MIT License | 5 votes |
def wordCloud(): logging.info("Generating wordCloud from text, cnt = %d", msgCnt) wordcloud = WordCloud(stopwords=STOPWORDS, width=800, height=400, background_color="white", max_words=1000).generate(wordText) logging.debug("wc freq %s: ", wordcloud.words_) wordcloud.to_file(mountPath + "/wordcloud.png")
Example #5
Source File: wc.py From xi-iot with MIT License | 5 votes |
def wordCloud2(): logging.info("Generating wordCloud from freq, cnt = %d", msgCnt) wordcloud = WordCloud(stopwords=STOPWORDS, width=800, height=400, background_color="white", max_words=1000).generate_from_frequencies(wordCounter) wordcloud.to_file(mountPath + "/wordcloud2.png")
Example #6
Source File: update.py From All-About-the-GAN with MIT License | 5 votes |
def update_wordcloud_title(): """ Update the figure wordcloud_title.jpg """ data = pd.read_csv('AllGAN-r2.tsv',delimiter='\t', encoding='utf-8') # tmp_data = data['Title'].split(" ") for x in data # count_list = list([list(x) for x in data['Title'].value_counts().reset_index().values]) # wordcloud = WordCloud(stopwords=STOPWORDS,relative_scaling = 0.2, # max_words=2000, background_color='white').generate_from_frequencies(tmp_data) stopwords = set(STOPWORDS) #ganstop = ['Generative','Adversarial', 'Networks', 'Network', 'GAN', 'GANs', 'using', 'Learning', 'Training', 'Generation', # 'Neural', 'Net', 'Model', 'Nets', 'Deep', 'Based', 'Via', 'Conditional', 'Models', 'Examples'] #stopwords.add(ganstop) stopwords.add('Generative') stopwords.add('Adversarial') stopwords.add('Networks') stopwords.add('Network') stopwords.add('GAN') stopwords.add('GANs') stopwords.add('using') stopwords.add('Learning') stopwords.add('Training') stopwords.add('Generation') stopwords.add('Neural') stopwords.add('Net') stopwords.add('Model') stopwords.add('Nets') stopwords.add('Deep') stopwords.add('Based') stopwords.add('Via') stopwords.add('Conditional') stopwords.add('Models') stopwords.add('Examples') wordcloud = WordCloud(stopwords=stopwords,relative_scaling = 0.2, random_state=3, max_words=2000, background_color='white').generate(' '.join(data['Title'])) plt.figure(figsize=(12,12)) plt.imshow(wordcloud, interpolation="bilinear") plt.axis("off") #plt.show() #plt.savefig('wordcloud_title.png') wordcloud.to_file('wordcloud_title.png') wordcloud.to_file('docs/png/wordcloud_title.png')
Example #7
Source File: update.py From All-About-the-GAN with MIT License | 5 votes |
def update_wordcloud_category(): """ Update the figure wordcloud_category.jpg """ data = pd.read_csv('AllGAN-r2.tsv',delimiter='\t', encoding='utf-8') wordcloud = WordCloud(stopwords=STOPWORDS,relative_scaling = 0.2, random_state=3, max_words=2000, background_color='white').generate(' '.join(data['Category'])) plt.figure(figsize=(12,12)) plt.imshow(wordcloud, interpolation="bilinear") plt.axis("off") #plt.show() #plt.savefig('wordcloud_title.png') wordcloud.to_file('wordcloud_category.png') wordcloud.to_file('docs/png/wordcloud_category.png')
Example #8
Source File: update.py From All-About-the-GAN with MIT License | 5 votes |
def update_wordcloud_abbr(): """ Update the figure wordcloud_category.jpg """ data = pd.read_csv('AllGAN-r2.tsv',delimiter='\t', encoding='utf-8') wordcloud = WordCloud(stopwords=STOPWORDS,relative_scaling = 0.2, random_state=3, max_words=2000, background_color='white').generate(' '.join(data['Abbr.'])) plt.figure(figsize=(12,12)) plt.imshow(wordcloud, interpolation="bilinear") plt.axis("off") #plt.show() #plt.savefig('wordcloud_title.png') wordcloud.to_file('wordcloud_abbr.png') wordcloud.to_file('docs/png/wordcloud_abbr.png')
Example #9
Source File: wc.py From xi-iot with MIT License | 4 votes |
def main(): global msgCnt global wordCounter global wordText logging.basicConfig(format='%(asctime)s %(levelname)s:%(message)s', level=logging.DEBUG) logging.info("Kafka Broker: %s", kafkaBroker) logging.info("Kafka Topic: %s", kafkaTopic) logging.info("Mount Path: %s", mountPath) createHtml() try: while True: # Read from kafkaTopic msg = readMsg() if msg is None: continue msgCnt += 1 # Update the global wordText wordText = wordText + ' ' + msg.lower().strip('\n') # generate wordCloud from text logging.info("wordText: %s", wordText) wordCloud() #method 2: generate freq here and pass it to wordcloud words = re.findall(r'\w+', msg.lower()) wordCount = [word for word in words if word not in STOPWORDS] c1 = Counter(wordCount) logging.debug("c1: %s", c1) # Update the global wordCounter wordCounter.update(c1) # generate wordCloud from frequencies logging.info("wordCounter: %s", wordCounter.most_common(20)) wordCloud2() finally: logging.debug("Closing consumer") kConsumer.close()