Python wordcloud 模块,STOPWORDS 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用wordcloud.STOPWORDS

项目:cloudy_search    作者:tim-shane    | 项目源码 | 文件源码
def create_cloud(self):
        # Return Bing search snippets
        text = self.return_txt()

        # Get mask image from Bing
        image_mask = np.array(self.return_img())

        # potential feature
        stopwords = set(STOPWORDS)
        # stopwords.add(search_modifier)

        wordcloud = WordCloud(background_color="white", mask=image_mask, stopwords=stopwords)
        wordcloud.generate(text)

        image_colors = ImageColorGenerator(image_mask)
        plt.imshow(image_mask, cmap=plt.cm.gray, interpolation="None")
        plt.imshow(wordcloud.recolor(color_func=image_colors), alpha=.8, interpolation='None')
        plt.axis("off")
        return plt
项目:FacebookGraphAPI-Examples    作者:nikhilkumarsingh    | 项目源码 | 文件源码
def wcloud(text):
     mask = np.array(Image.open("face_mask.png"))   #choose mask
     stopwords = set(STOPWORDS)
     wc = WordCloud(background_color="white",
                    mask=mask,
                    max_words=80,
                    stopwords=stopwords,
                    width=800,
                    height=400,
                    mode="RGB",
                    relative_scaling=0.5,
                    )

     text = clean_text(text)
     wc.generate(text)

     #save image
     file_name = raw_input("Enter any name for the Word Cloud image:") +'.png'    
     wc.to_file(file_name)

     return
项目:TwitterPeruser    作者:ilyauts    | 项目源码 | 文件源码
def generateWordCloud(text):
    # read the mask / color image
    # taken from http://jirkavinse.deviantart.com/art/quot-Real-Life-quot-Alice-282261010
    d = path.dirname(__file__)

    cloud_coloring = np.array(Image.open(path.join(d, "us-mask-white.png")))
    stopwords = set(STOPWORDS)
    stopwords.add("said")

    wc = WordCloud(background_color="black", max_words=2000, mask=cloud_coloring,
                   stopwords=stopwords, max_font_size=40, random_state=42)
    # generate word cloud
    wc.generate(text)

    # create coloring from image
    image_colors = ImageColorGenerator(cloud_coloring)

    # show
    plt.imshow(wc)
    plt.axis("off")
    plt.show()
项目:TwitterPeruser    作者:ilyauts    | 项目源码 | 文件源码
def generateTable(text, n=5):
    # Start by getting a frequency dictionary
    d = path.dirname(__file__)

    cloud_coloring = np.array(Image.open(path.join(d, "us-mask-white.png")))
    stopwords = set(STOPWORDS)
    stopwords.add("said")

    wc = WordCloud(background_color="black", max_words=2000, mask=cloud_coloring,
                   stopwords=stopwords, max_font_size=40, random_state=42)

    frequenciesDict = wc.process_text(text)

    words = frequenciesDict.keys()
    freq = frequenciesDict.values()

    frequencies = pd.DataFrame({ 'words' : words, 'frequencies' : freq })
    frequencies.sort_values('frequencies', ascending = False, inplace = True)

    print '\nTop 5 Terms\n'
    print frequencies.head(n = n).to_string(index = False)
    print '\n'
项目:lianjia    作者:learrn    | 项目源码 | 文件源码
def title_word_cloud():
    """
    ???????
    """
    text = ''
    wc = WordCloud(background_color='white',  # ??????
                   stopwords=STOPWORDS,
                   max_words=1000,  # ?????????
                   font_path='C:/Python27/Lib/site-packages/matplotlib/mpl-data/fonts/ttf/simhei.ttf',
                   # ?????????????????
                   max_font_size=50,  # ???????
                   random_state=30,  # ??????????????????????
                   )
    with open('rent_ave.csv') as csvfile:
        reader = [each for each in csv.DictReader(csvfile)]
    for row in reader:
        text += row[u'title'] + ' '
    print jieba_clear_text(text)
    wc.generate(jieba_clear_text(text))
    plt.imshow(wc)
    plt.axis('off')
    plt.show()
项目:InterestingCrawler    作者:Maicius    | 项目源码 | 文件源码
def drawWordCloud(word_text, filename):
    mask = imread('hello.jpg')
    my_wordcloud = WordCloud(
        background_color='white',  # ??????
        mask=mask,  # ??????
        max_words=2000,  # ?????????
        stopwords=STOPWORDS,  # ?????
        font_path='/System/Library/Fonts/Hiragino Sans GB W6.ttc',  # ?????????????????
        max_font_size=50,  # ???????
        random_state=30,  # ??????????????????????
        scale=1
    ).generate(word_text)
    image_colors = ImageColorGenerator(mask)
    my_wordcloud.recolor(color_func=image_colors)
    # ????????
    plt.imshow(my_wordcloud)
    plt.axis("off")
    plt.show()
    # ????
    my_wordcloud.to_file(filename=filename)
    print()
项目:InterestingCrawler    作者:Maicius    | 项目源码 | 文件源码
def drawWordCloud(word_text, filename):
    mask = imread('bike.jpg')
    my_wordcloud = WordCloud(
        background_color='white',  # ??????
        mask=mask,  # ??????
        max_words=2000,  # ?????????
        stopwords=STOPWORDS,  # ?????
        font_path='/System/Library/Fonts/Hiragino Sans GB W6.ttc',  # ?????????????????
        max_font_size=50,  # ???????
        random_state=30,  # ??????????????????????
        scale=1.3
    ).generate(word_text)
    image_colors = ImageColorGenerator(mask)
    my_wordcloud.recolor(color_func=image_colors)
    # ????????
    plt.imshow(my_wordcloud)
    plt.axis("off")
    plt.show()
    # ????
    my_wordcloud.to_file(filename=filename)
    print()