• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pytagcloud.create_tag_image函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pytagcloud.create_tag_image函数的典型用法代码示例。如果您正苦于以下问题:Python create_tag_image函数的具体用法?Python create_tag_image怎么用?Python create_tag_image使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了create_tag_image函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: search

def search(query_word):
	result = []
	es = Elasticsearch()
	query1 = {"query": {"wildcard": {"name": {"value": "*" + query_word + "*" } } } }
	res = es.search(index="urban", body=query1)

	if res['hits']['total'] == 0:
		res = es.search(index="champ", body=query1)

	if res['hits']['total'] == 0:
		return 0

	ret = res['hits']['hits']

	temp = defaultdict(int)
	for item in ret:
		ids = item['_source']['business_id']
		query2 = {"query":  {"match": {"business_id": ids } } }
		res = es.search(index="my_data", body=query2)

		for item in res['hits']['hits'][0]['_source']['word_freq']:
			temp[item[0]] += item[1]

	words = []
	for item in temp:
		words.append((item,temp[item]))

	tags = make_tags(words, maxsize=80)

	create_tag_image(tags, 'static/cloud_large.jpg', size=(900, 600), fontname='Lobster')
开发者ID:neostoic,项目名称:DataVisualizerHack,代码行数:30,代码来源:searchapi.py


示例2: make_tag_cloud

def make_tag_cloud(data, can_be_noun_arg, process_option='freqs'):
    stop_words = sw.words()
    process_f = {
            'concatenate': lambda : concatenate(data, can_be_noun_arg, stop_words),
            'freqs': lambda : freq_weight(data, can_be_noun_arg, stop_words),
            'race' : lambda : race_tfidf(data, can_be_noun_arg, stop_words)
    }
    freqs = process_f[process_option]()
    if type(freqs) == type([]):
        freqs = freqs[:30]
        # normalize freqs in case they are counts
        sum_freqs = np.sum(x for _,x in freqs)
        freqs = [(w, np.float(f)/sum_freqs) for w,f in freqs]
        #pprint(freqs)
        #return
        tags = make_tags(freqs, maxsize=80)
        fname = 'noun_last_words_{}.png'.format(process_option)
        if not can_be_noun_arg:
            fname = 'not_'+fname
        create_tag_image(tags, fname, size=(900, 600), fontname='Lobster')
    elif type(freqs)==type({}):
        for k in freqs:
            top_freqs = freqs[k][:30]
            # normalize    
            sum_freqs = np.sum(x for _,x in top_freqs)
            top_freqs = [(w, np.float(f)/sum_freqs) for w,f in top_freqs]
            print top_freqs
            tags = make_tags(top_freqs, maxsize=15)
            fname = 'noun_last_words_{}_{}.png'.format(process_option,k)
            create_tag_image(tags, fname, size=(900, 600), fontname='Lobster')
开发者ID:raresct,项目名称:last_words,代码行数:30,代码来源:last_words.py


示例3: create_cloud

def create_cloud(oname, words,maxsize=120, fontname='Lobster'):
    '''Creates a word cloud (when pytagcloud is installed)

    Parameters
    ----------
    oname : output filename
    words : list of (value,str)
    maxsize : int, optional
        Size of maximum word. The best setting for this parameter will often
        require some manual tuning for each input.
    fontname : str, optional
        Font to use.
    '''
    try:
        from pytagcloud import create_tag_image, make_tags
    except ImportError:
        if not warned_of_error:
            print("Could not import pytagcloud. Skipping cloud generation")
        return

    # gensim는 각 단어에 대해 0과 1사이의 가중치를 반환하지만 
    # pytagcloud는 단어 수를 받는다. 그래서 큰 수를 곱한다
    # gensim는 (value, word)를 반환하고 pytagcloud는 (word, value)으로 입력해야 한다
    words = [(w,int(v*10000)) for v,w in words]
    tags = make_tags(words, maxsize=maxsize)
    create_tag_image(tags, oname, size=(1800, 1200), fontname=fontname)
开发者ID:flyingbest,项目名称:machine-learning,代码行数:26,代码来源:wordcloud.py


示例4: generate_word_cloud

def generate_word_cloud(counts, title):
	# Sort the keywords
	sorted_wordscount = sorted(counts.iteritems(), key=operator.itemgetter(1), reverse=True)[:20]
	
	# Generate the word cloud image
	create_tag_image(make_tags(sorted_wordscount, minsize=50, maxsize=150), title + '.png', size=(1300,1150), 
		background=(0, 0, 0, 255), layout=LAYOUT_MIX, fontname='Molengo', rectangular=True)
开发者ID:eco2116,项目名称:Storytelling-Final-Project,代码行数:7,代码来源:articles.py


示例5: make_cloud

    def make_cloud(self, output_html):
        keywords = KeywordManager().all()
        text = ' '.join([kw.keyword for kw in keywords])

        if output_html:
            max_tags = 30
            max_size = 42
        else:
            max_tags = 100
            max_size = self.maxsize

        tags = make_tags(get_tag_counts(text)[:max_tags], minsize=self.minsize,
                         maxsize=max_size)

        if output_html:
            size = (900, 300)
            result = create_html_data(tags, size=size,
                                      layout=LAYOUT_HORIZONTAL)
        else:
            #now = datetime.utcnow()
            #filename = 'jcuwords/static/clouds/keyword-cloud-%s.png' % now.isoformat()
            cloud = self.resolver.resolve('jcuwords:keyword-cloud.png')
            filename = cloud.abspath()
            size = (1024, 500)
            create_tag_image(tags, filename, size=size,
                             fontname='IM Fell DW Pica',
                             layout=LAYOUT_MIX)
            image_url = self.request.resource_url(None, 'keyword-cloud.png')
            result = {'image': image_url}

        return result
开发者ID:jcu-eresearch,项目名称:jcu.words,代码行数:31,代码来源:views.py


示例6: createTagCloud

 def createTagCloud(self,wordline):
     """
     Create tag cloud image 
     """
     wordstream = []
     if wordline == '':
         return False
     
     wordsTokens = WhitespaceTokenizer().tokenize(wordline)
     wordsTokens.remove(wordsTokens[0])
     wordstream.append(' '.join(wordsTokens))
     wordstream = ' '.join(wordstream)
     thresh = self.wordCount
     colorS = self.colorSchemes[self.color]
     
     tags = make_tags(get_tag_counts(wordstream)[:thresh],\
                      minsize=3, maxsize=40,\
                      colors = COLOR_SCHEMES[colorS])
     
     create_tag_image(tags, self.png,\
                      size=(960, 400),\
                      background=(255, 255, 255, 255),\
                      layout= LAYOUT_HORIZONTAL,\
                      fontname='Neuton')
     return True
开发者ID:BloodD,项目名称:PyTopicM,代码行数:25,代码来源:wordCloudDraw.py


示例7: _create_image

    def _create_image(self, text):
        tag_counts = get_tag_counts(text)
        if tag_counts is None:
            sys.exit(-1)

        if self._repeat_tags:
            expanded_tag_counts = []
            for tag in tag_counts:
                expanded_tag_counts.append((tag[0], 5))
            for tag in tag_counts:
                expanded_tag_counts.append((tag[0], 2))
            for tag in tag_counts:
                expanded_tag_counts.append((tag[0], 1))
            tag_counts = expanded_tag_counts

        tags = make_tags(tag_counts, maxsize=150, colors=self._color_scheme)
        path = os.path.join('/tmp/cloud_large.png')

        if Gdk.Screen.height() < Gdk.Screen.width():
            height = Gdk.Screen.height()
            width = int(height * 4 / 3)
        else:
            width = Gdk.Screen.width()
            height = int(width * 3 / 4)

        if self._font_name is not None:
            create_tag_image(tags, path, layout=self._layout,
                             size=(width, height),
                             fontname=self._font_name)
        else:
            create_tag_image(tags, path, layout=self._layout,
                             size=(width, height))
        return 0
开发者ID:sugarlabs,项目名称:wordcloud,代码行数:33,代码来源:wordcloud.py


示例8: tagCloud

    def tagCloud(self):
        texts =""
        for item in self.docSet:
            texts = texts +" " +item

        tags = make_tags(get_tag_counts(texts), maxsize=120)
        create_tag_image(tags,'filename.png', size=(2000,1000), background=(0, 0, 0, 255), layout=LAYOUT_MIX, fontname='Lobster', rectangular=True)
开发者ID:prathmeshgat,项目名称:SuicidalPersonDetection,代码行数:7,代码来源:TagCloud.py


示例9: word_cloud

def word_cloud(final_object, cloud_object):

    import re
    from pytagcloud.lang.stopwords import StopWords
    from operator import itemgetter
    final_object = [x for x in final_object if x != "no_object"]


    counted = {}

    for word in final_object:
        if len(word) > 1:
            if counted.has_key(word):
                counted[word] += 1
            else:
                counted[word] = 1
    #print len(counted)

    counts = sorted(counted.iteritems(), key=itemgetter(1), reverse=True)

    print "Total count of Word Cloud List Items: ",counts
    #type(counts)

    words = make_tags(counts, maxsize=100)
    print "Word Cloud List items: ", words


    create_tag_image(words, 'cloud_1_All_Objects.png', size=(1280, 900), fontname='Lobster')

    width = 1280
    height = 800
    layout = 3
    background_color = (255, 255, 255)
开发者ID:nus-iss-ca,项目名称:text-mining,代码行数:33,代码来源:Q2-Objects_Extraction.py


示例10: plot

def plot(game_name, game_id):
    dict = {}
    comments = DbUtil.getAllResult("select * from comment where game_id = %s" % game_id)
    for comment in comments:

        result = jieba.analyse.extract_tags(comment[2], topK=3)

        for word in result:
            if len(word) < 2:
                continue
            elif word in stop:
                continue

            if word not in dict:
                dict[word] = 1
            else:
                dict[word] += 1

    print(dict)

    swd = sorted(dict.items(), key=itemgetter(1), reverse=True)
    swd = swd[1:50]
    tags = make_tags(swd,
                     minsize=30,
                     maxsize=120,
                     colors=random.choice(list(COLOR_SCHEMES.values())))

    create_tag_image(tags,
                     'c:/%s.png' % game_name,
                     background=(0, 0, 0, 255),
                     size=(900, 600),
                     fontname='SimHei')

    print('having save file to dick')
开发者ID:WhiteDevilBan,项目名称:CommentCrawler,代码行数:34,代码来源:CreateWordCloud.py


示例11: wordcloud

def wordcloud(query, layout, font, max_words, verbosity=False):
    my_oauth, complete_url, stop_words = twitter(query)
    punctuation = "#@!\"$%&'()*+,-./:;<=>?[\]^_`{|}~\'"  # characters exluded from tweets
    my_text = ''
    r = requests.get(complete_url, auth=my_oauth)
    tweets = r.json()
    if verbosity == True:
        print tweets
    for tweet in tweets['statuses']:
        text = tweet['text'].lower()
        text = ''.join(ch for ch in text if ch not in punctuation)  # exclude punctuation from tweets
        my_text += text

    words = my_text.split()
    counts = Counter(words)
    for word in stop_words:
        del counts[word]

    for key in counts.keys():
        if len(key) < 3 or key.startswith('http'):
            del counts[key]

    final = counts.most_common(max_words)
    max_count = max(final, key=operator.itemgetter(1))[1]
    final = [(name, count / float(max_count))for name, count in final]
    tags = make_tags(final, maxsize=max_word_size)
    create_tag_image(tags, query + '.png', size=(width, height), layout=layout, fontname=font, background=background_color)
    print "new png created"
开发者ID:IndicoDataSolutions,项目名称:sentimentalCloud,代码行数:28,代码来源:sentimentalCloud.py


示例12: create_cloud

def create_cloud(oname, words,maxsize=120, fontname='Lobster'):
    '''Creates a word cloud (when pytagcloud is installed)

    Parameters
    ----------
    oname : output filename
    words : list of (value,str)
    maxsize : int, optional
        Size of maximum word. The best setting for this parameter will often
        require some manual tuning for each input.
    fontname : str, optional
        Font to use.
    '''
    try:
        from pytagcloud import create_tag_image, make_tags
    except ImportError:
        if not warned_of_error:
            print("Could not import pytagcloud. Skipping cloud generation")
        return

    # gensim returns a weight between 0 and 1 for each word, while pytagcloud
    # expects an integer word count. So, we multiply by a large number and
    # round. For a visualization this is an adequate approximation.
    words = [(w,int(v*10000)) for w,v in words]
    tags = make_tags(words, maxsize=maxsize)
    create_tag_image(tags, oname, size=(1800, 1200), fontname=fontname)
开发者ID:Let4ik,项目名称:BuildingMachineLearningSystemsWithPython,代码行数:26,代码来源:wordcloud.py


示例13: _test_large_tag_image

 def _test_large_tag_image(self):
     start = time.time()
     tags = make_tags(get_tag_counts(self.hound.read())[:80], maxsize=120, 
                      colors=COLOR_SCHEMES['audacity'])
     create_tag_image(tags, os.path.join(self.test_output, 'cloud_large.png'), 
                      ratio=0.75, background=(0, 0, 0, 255), 
                      layout=LAYOUT_HORIZONTAL, fontname='Lobster')
     print "Duration: %d sec" % (time.time() - start)
开发者ID:johnlaudun,项目名称:PyTagCloud,代码行数:8,代码来源:tests.py


示例14: test_layouts

 def test_layouts(self):
     start = time.time()
     tags = make_tags(get_tag_counts(self.hound.read())[:80], maxsize=120)
     for layout in LAYOUTS:
         create_tag_image(tags, os.path.join(self.test_output, 'cloud_%s.png' % layout),
                          size=(900, 600),
                          background=(255, 255, 255, 255),
                          layout=layout, fontname='Lobster')
     print "Duration: %d sec" % (time.time() - start)
开发者ID:mycguo,项目名称:PyTagCloud,代码行数:9,代码来源:tests.py


示例15: make_tag_cloud

def make_tag_cloud(): 
    for line in sys.stdin:
        try: 
            text += ' ' + line.strip().lower()
        except:
            pass
    
    tags = make_tags(get_tag_counts(text), maxsize=150)
    create_tag_image(tags, sys.argv[1] + '.png', size=(1024, 768))
开发者ID:gsm1011,项目名称:crawl.twitter,代码行数:9,代码来源:cloud.py


示例16: create_cloud

def create_cloud(counter, filename):
    '''
    Creates a word cloud from a counter
    '''
    tags = make_tags(get_tag_counts(counter)[:80], maxsize=120, 
                     colors=COLOR_SCHEMES['goldfish'])
    create_tag_image(tags, './img/' + filename + '.png', 
                     size=(900, 600), background=(0, 0, 0, 255), 
                     layout=LAYOUT_HORIZONTAL, fontname='Lobster')
开发者ID:kqdtran,项目名称:FTES,代码行数:9,代码来源:ftes.py


示例17: build_pytag_cloud

 def build_pytag_cloud(self):
   width = 900
   height = 575
   fileName = '{0}/{1}.{2}.{3}.{4}.png'.format(self.img_directory, self.state, self.city, width, height)
   items = sorted(self.tagcloud.iteritems(), key=itemgetter(1), reverse=True)
   tags = make_tags(items[:self.wordcount], maxsize=80)
   create_tag_image(tags, fileName, size=(width, height), fontname='Droid Sans')
   import webbrowser
   webbrowser.open(fileName) # see results
开发者ID:mitch-b,项目名称:fcc-comments-tagcloud,代码行数:9,代码来源:tagcloud_builder.py


示例18: semantic_cloud

def semantic_cloud(topic):
    topic_list = TopicList(topic)
    tlist = topic_list.GetTopicList()
    htagsl = HashtagsList(tlist['statuses'], topic)
    hl = htagsl.GetHashtagsList()
    cadena = " ".join(hl)
    print cadena
    tags = make_tags(get_tag_counts(cadena), maxsize=120)
    create_tag_image(tags, 'semantic_cloud.png', size=(900, 600), fontname='Lobster')
开发者ID:Pycero91,项目名称:Segundo,代码行数:9,代码来源:ClassPyTw+V3.py


示例19: make_cloud

def make_cloud(text,fname):
    '''create the wordcloud from variable text'''
    Data1 = text.lower().replace('http','').replace('rt ','').replace('.co','')
    Data = Data1.split()
    two_words = [' '.join(ws) for ws in zip(Data, Data[1:])]
    wordscount = {w:f for w, f in collections.Counter(two_words).most_common() if f > 200}
    sorted_wordscount = sorted(wordscount.iteritems(), key=operator.itemgetter(1),reverse=True)

    tags = make_tags(get_tag_counts(Data1)[:50],maxsize=350,minsize=100)
    create_tag_image(tags,fname+'.png', size=(3000,3250), background=(0, 0, 0, 255), layout=LAYOUT_MIX, fontname='Lobster', rectangular=True)
开发者ID:Maikflow,项目名称:freelancer_jobs,代码行数:10,代码来源:tagcloud.py


示例20: makeCloud

    def makeCloud(self, tagsCounts, name="tag_cloud.png", height=500,\
        width=500, font="Droid Sans"):

        # Get rid of unigrams contained in bigrams
        tagsCounts = self.parseWords(tagsCounts)

        tags = pytagcloud.make_tags(tagsCounts, colors=self._colors)

        pytagcloud.create_tag_image(tags, name, size=(width, height),\
            fontname=font, rectangular=True)
开发者ID:ddexter,项目名称:RSS,代码行数:10,代码来源:tagCloud.py



注:本文中的pytagcloud.create_tag_image函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pytagcloud.make_tags函数代码示例发布时间:2022-05-27
下一篇:
Python extraviews.tadbit_savefig函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap