當前位置: 首頁>>代碼示例>>Python>>正文


Python wordcloud.STOPWORDS屬性代碼示例

本文整理匯總了Python中wordcloud.STOPWORDS屬性的典型用法代碼示例。如果您正苦於以下問題:Python wordcloud.STOPWORDS屬性的具體用法?Python wordcloud.STOPWORDS怎麽用?Python wordcloud.STOPWORDS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在wordcloud的用法示例。


在下文中一共展示了wordcloud.STOPWORDS屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: generate_wordcloud

# 需要導入模塊: import wordcloud [as 別名]
# 或者: from wordcloud import STOPWORDS [as 別名]
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) 
開發者ID:hubertjb,項目名稱:dl-eeg-review,代碼行數:26,代碼來源:analysis.py

示例2: drawWordCloud

# 需要導入模塊: import wordcloud [as 別名]
# 或者: from wordcloud import STOPWORDS [as 別名]
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') 
開發者ID:Maicius,項目名稱:QQZoneMood,代碼行數:40,代碼來源:QQZoneAnalysis.py

示例3: show

# 需要導入模塊: import wordcloud [as 別名]
# 或者: from wordcloud import STOPWORDS [as 別名]
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() 
開發者ID:ZubinGou,項目名稱:AI_Poet_Totoro,代碼行數:37,代碼來源:歌詞_6詞雲.py

示例4: wordCloud

# 需要導入模塊: import wordcloud [as 別名]
# 或者: from wordcloud import STOPWORDS [as 別名]
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") 
開發者ID:nutanix,項目名稱:xi-iot,代碼行數:7,代碼來源:wc.py

示例5: wordCloud2

# 需要導入模塊: import wordcloud [as 別名]
# 或者: from wordcloud import STOPWORDS [as 別名]
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") 
開發者ID:nutanix,項目名稱:xi-iot,代碼行數:6,代碼來源:wc.py

示例6: update_wordcloud_category

# 需要導入模塊: import wordcloud [as 別名]
# 或者: from wordcloud import STOPWORDS [as 別名]
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') 
開發者ID:hollobit,項目名稱:All-About-the-GAN,代碼行數:17,代碼來源:update.py

示例7: update_wordcloud_abbr

# 需要導入模塊: import wordcloud [as 別名]
# 或者: from wordcloud import STOPWORDS [as 別名]
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') 
開發者ID:hollobit,項目名稱:All-About-the-GAN,代碼行數:17,代碼來源:update.py

示例8: main

# 需要導入模塊: import wordcloud [as 別名]
# 或者: from wordcloud import STOPWORDS [as 別名]
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() 
開發者ID:nutanix,項目名稱:xi-iot,代碼行數:47,代碼來源:wc.py

示例9: update_wordcloud_title

# 需要導入模塊: import wordcloud [as 別名]
# 或者: from wordcloud import STOPWORDS [as 別名]
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') 
開發者ID:hollobit,項目名稱:All-About-the-GAN,代碼行數:49,代碼來源:update.py


注:本文中的wordcloud.STOPWORDS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。