当前位置: 首页>>代码示例>>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;未经允许,请勿转载。