python类WordCloud()的实例源码

wordcloud.py 文件源码 项目:EnglishDiary 作者: jupiny 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def set_wordcloud_image(words):

    if words:
        # WordCloud Option
        wc = WordCloud(
            background_color=settings.WORDCLOUD_BACKGROUND_COLOR,
            width=settings.WORDCLOUD_WIDTH,
            height=settings.WORDCLOUD_HEIGHT,
            max_words=settings.WORDCLOUD_MAX_WORDS,
            max_font_size=settings.WORDCLOUD_MAX_FRONT_SIZE,
            scale=settings.WORDCLOUD_SCALE,
        )
        wordcloud_img = wc.generate(words).to_image()
        return wordcloud_img
    return None
graphs.py 文件源码 项目:wntf 作者: tonybaloney 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def word_cloud(f):
    wordcloud = WordCloud().generate_from_frequencies(f)
    # Open a plot of the generated image.
    plt.imshow(wordcloud)
    plt.axis("off")
    plt.savefig('out/word_cloud.png', dpi=300, format='png')
rekognition_video.py 文件源码 项目:rekognition-video-utils 作者: awslabs 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def generate_wordcloud():
    from wordcloud import WordCloud
    wordcloud = WordCloud(background_color="white")

    from operator import itemgetter
    item1 = itemgetter(1)
    frequencies = sorted(label_counts.items(), key=item1, reverse=True)
    wordcloud.generate_from_frequencies(frequencies)

    # save image
    import matplotlib.pyplot as plt
    plt.imshow(wordcloud)
    plt.axis("off")
    plt.savefig('photo_tags')
gctag.py 文件源码 项目:gctag 作者: Fenghuapiao 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--url', metavar='URL', default=None, help='input the url')
    parser.add_argument('--output', metavar='OUTPUT', default='./wordcloud.jpg', help='input the output_file')
    parser.add_argument('--input', metavar='INPUT_FIEL', default=None, help='input the input_file')
    parser.add_argument('--model', metavar='INPUT_IMAGE_MODEL', default=None, help='input the input_image_model')
    parser.add_argument('--ttf', metavar='INPUT_TTF', default='./font/simhei.ttf', help='input the typeface')
    parser.add_argument('--width', metavar='INPUT_WIDTH', default=1800, type=int, help='input the image width')
    parser.add_argument('--height', metavar='INPUT_HEIGHT', default=1000, type=int, help='input the image height')
    parser.add_argument('--bg', metavar='INPUT_BACKGROUND_COLOR', default='black', help='input the image background_color')
    parser.add_argument('--margin', metavar='INPUT_MARGIN', default=5, type=int, help='input the image margin')
    parser.add_argument('--max_font_size', metavar='INPUT_max_font_size', default=60, type=int, help='input the max_font_size')
    args = parser.parse_args()

    url = args.url
    output_file = args.output
    input_file = args.input
    model_path = args.model
    typeface = args.ttf
    max_font_size=args.max_font_size
    width = args.width
    height = args.height
    background_color = args.bg
    margin = args.margin

    try:
        image_mask = np.array(PIL.Image.open(model_path))
    except:
        image_mask=None

    wordcloud = WordCloud(font_path=typeface, mask=image_mask, max_font_size=max_font_size,
                          background_color=background_color, margin=margin, width=width, height=height)
    try:
        txt_join = get_txt(input_file)
        wordcloud_ = wordcloud.generate(txt_join)
    except:
        html_text = get_html_text(url)
        wordcloud_ = wordcloud.generate(html_text)

    image = wordcloud_.to_image()
    image.save(output_file)
word_cloud.py 文件源码 项目:jd_spider 作者: roxylu 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def show(self):
        wordcloud = WordCloud(
            font_path=u'./static/simheittf/simhei.ttf',
            background_color="black", max_words=40, margin=5, width=1000, height=800)

        wordcloud = wordcloud.generate(self.seg_text)

        plt.figure()
        plt.imshow(wordcloud)
        plt.axis("off")
        plt.show()
word_cluster.py 文件源码 项目:PolBotCheck 作者: codeforfrankfurt 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def save_wordcloud_image(frequencies, filename):
    wordcloud = WordCloud(width=1024, height=786, min_font_size=1).fit_words(frequencies)
    fig = plt.figure()
    fig.set_figwidth(12)
    fig.set_figheight(16)
    plt.imshow(wordcloud)
    plt.axis("off")
    plt.savefig(filename, facecolor='k', bbox_inches='tight')
    print('imaged created')
words_image.py 文件源码 项目:words_image 作者: flingjie 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def generate_image(words, image):
    graph = np.array(image)
    wc = WordCloud(font_path=os.path.join(CUR_DIR, 'fonts/simhei.ttf'),
                   background_color='white', max_words=MAX_WORDS, mask=graph)
    wc.generate_from_frequencies(words)
    image_color = ImageColorGenerator(graph)
    return wc, image_color
wordc.py 文件源码 项目:jaychou 作者: fantasysea 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def wordcloudplot(txt,name):
    path = 'msyh.ttf'
    path = unicode(path, 'utf8').encode('gb18030')
    alice_mask = np.array(PIL.Image.open('jay.jpg'))
    wordcloud = WordCloud(font_path=path,
                          background_color="white",
                          margin=5, width=1800, height=800, mask=alice_mask, max_words=2000, max_font_size=60,
                          random_state=42)
    wordcloud = wordcloud.generate(txt)
    wordcloud.to_file('../songs/'+name+'/'+name+'.jpg')
    plt.imshow(wordcloud)
    plt.axis("off")
    plt.show()
util_csl.py 文件源码 项目:Medium-crawler-with-data-analyzer 作者: lifei96 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_wordcloud(file_path):
    with open(file_path, 'r') as f:
        text = f.read()
    wordcloud = WordCloud(max_font_size=200, min_font_size=25, prefer_horizontal=1, background_color='white', margin=0,
                          relative_scaling=0.5, colormap='copper', collocations=False, width=1600, height=800).generate(text)
    plt.figure()
    plt.imshow(wordcloud, interpolation="bilinear")
    plt.axis("off")
    plt.show()
wordart.py 文件源码 项目:csss-minion 作者: henrymzhao 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def createImage(self, arr, saveName):
        text = " ".join(arr)
        savedir = path.join(self.d,self.e, saveName) # local image gets overwritten each time. will this break if too many requests?
        wc = WordCloud(max_words=20000, stopwords=self.STOPWORDS).generate(text)
        wc.to_file(savedir)
        return savedir


        # idk how it subscribes to the event... but it works!
MyCloud.py 文件源码 项目:Tweet_cloud 作者: yashasingh 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def generate(self, title, text):
        wordcloud = WordCloud(max_font_size=40).generate(text)
        plt.figure()
        plt.imshow(wordcloud, interpolation='bilinear')
        plt.axis("off")
        # plt.show()
        filename = title + '.png'
        plt.savefig(filename,  bbox_inches='tight')
mywordCloud.py 文件源码 项目:warWolf 作者: wu-yy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def draw_wordcloud(file_name):
    with codecs.open(file_name,encoding='utf-8') as f:
        comment_text=f.read()
    color_mask=imread('template.png') #??????
    stopwords = ['png','douban','com','href','https','img','img3','class','source','icon','shire',u'??',u'??',u'??',u'??',u'??',u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??',
                 u'??', u'??', u'??', u'??']
    font = r'C:\Windows\Fonts\simfang.ttf'
    cloud=WordCloud(font_path=font,background_color='white',max_words=20000,max_font_size=200,min_font_size=4,mask=color_mask,stopwords=stopwords)
    word_cloud=cloud.generate(comment_text)  #????
    word_cloud.to_file('pjl_cloud.jpg')
mywordCloud.py 文件源码 项目:warWolf 作者: wu-yy 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def draw_wordcloud(file_name):
    with codecs.open(file_name,encoding='utf-8') as f:
        comment_text=f.read()
    color_mask=imread('template.png') #??????
    stopwords = [u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??', u'??',
                 u'??', u'??', u'??', u'??']
    font = r'C:\Windows\Fonts\simfang.ttf'
    cloud=WordCloud(font_path=font,background_color='white',max_words=20000,max_font_size=200,min_font_size=4,mask=color_mask,stopwords=stopwords)
    word_cloud=cloud.generate(comment_text)  #????
    word_cloud.to_file('pjl_cloud.jpg')
wordcloud.py 文件源码 项目:danmuWordCloud 作者: yutiansut 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def show(self):
        # wordcloud = WordCloud(max_font_size=40, relative_scaling=.5)
        wordcloud = WordCloud(font_path=u'./static/simheittf/simhei.ttf',
                              background_color="black", margin=5, width=1800, height=800)

        wordcloud = wordcloud.generate(self.seg_text)

        plt.figure()
        plt.imshow(wordcloud)
        plt.axis("off")
        plt.show()
word_3.py 文件源码 项目:text_analysis 作者: mathlf2015 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get_wordclud(file_set):
    line_set = []
    for j in range(10):
        reader=csv.reader(open(file_set[j], 'r'))
        for line in reader:
            line_set.append(line[1])
    word_list = [" ".join(jieba.cut(sentence)) for sentence in line_set]
    new_text = ' '.join(word_list)
    wordcloud = WordCloud(font_path="C:/Python34/Lib/site-packages/wordcloud/simhei.ttf", background_color="black").generate(new_text)
    plt.imshow(wordcloud)
    plt.axis("off")
    plt.show()
gen_wordcloud.py 文件源码 项目:es_email_intel 作者: xujun10110 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def gen_wordcloud():

    then = common_functions.queryrange(1)

    body = '''{
        "size" : 10000,
        "query": {
            "constant_score": {
                "filter": {
                    "range": {
                        "epoch": {
                            "from": '''+then+'''
                        }
                    }
                }
            }
        }
    }'''

    text = common_functions.pull_mailtext_24hrs(es, es_collection_name, body, keywords_list).lower()

    print text
    print

    wc = WordCloud(background_color="white", max_words=40)
    fileloc = "/home/pierre/es_email_intel/wordcloud.png"
    try:
        wc.generate(text)
        wc.to_file(fileloc)
        print 'Finished!'
        return
    except:
        target = open(fileloc, 'w')
        target.truncate()
        target.close()
        print 'Except!'
        return
buganlyze.py 文件源码 项目:EduSpider 作者: hlpureboy 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def drawPic(text,Pic):
    #img=imread(Pic,flatten=True)
    w=WordCloud(font_path="C:/Windows/Fonts/simhei.ttf",background_color='white').generate(text)
    plt.imshow(w)
    plt.axis("off")
    plt.savefig("F:/EduSpider/edubug.jpg",dpi=600)
data_desc_process.py 文件源码 项目:lagou_data_analysis 作者: jasminecjc 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_word_to_cloud(self):
        for file in self.file_list:
            with codecs.open('../spider/' + file, "r",encoding='utf-8', errors='ignore') as string:
                #??????????????????
                string = string.read().upper()
                #???????????
                res = jieba.cut(string, HMM=False)
                reslist = list(res)
                wordDict = {}
                #???????????
                for i in reslist:
                    if i not in self.dic_list:
                        continue
                    if i in wordDict:
                        wordDict[i]=wordDict[i]+1
                    else:
                        wordDict[i] = 1
            #???????
            coloring = imread('test.jpeg')
            #???????????????
            wc = WordCloud(font_path='msyh.ttc',mask=coloring,
                    background_color="white", max_words=50,
                    max_font_size=40, random_state=42)

            wc.generate_from_frequencies(wordDict)
            #????
            wc.to_file("%s.png"%(file))
#???????
GroupTagCloud.py 文件源码 项目:WechatForwardBot 作者: grapeot 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, fontPath):
        self.client = MongoClient()
        self.coll = self.client[dbName][collName]
        self.fontPath = fontPath
        self.wordCloud = WordCloud(font_path=self.fontPath, width=400, height=400, max_words=100)
        if not os.path.exists(self.imgDir):
            os.mkdir(self.imgDir)
        logging.info('GroupTagCloud connected to MongoDB.')
main.py 文件源码 项目:notebook 作者: archever 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def generate_img(data):
    mask_img = imread('./heart-mask.jpg')
    wordcloud = WordCloud(
        font_path='/Library/Fonts/Songti.ttc',
        background_color='white',
        mask=mask_img
    ).generate(data)
    plt.imshow(wordcloud)
    plt.axis('off')
    # plt.show()
    plt.savefig('./heart.jpg', dpi=600)


问题


面经


文章

微信
公众号

扫码关注公众号