Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Tag Cloud in Python

I am looking for a simple library which can be given a set of items:value pair and which can generate a tag cloud as output.

Library can preferably be in python

like image 549
demos Avatar asked Jul 05 '10 15:07

demos


People also ask

What is tag cloud in Python?

What is WordCloud? Many times you might have seen a cloud filled with lots of words in different sizes, which represent the frequency or the importance of each word. This is called Tag Cloud or WordCloud. For this tutorial, you will learn how to create a WordCloud of your own in Python and customize it as you see fit.


1 Answers

Define font-sizes in your css-file. Use classes from

size-0{
   font-size: 11px;
}

size-1{
   font-size: 12px;
}

etc. up to the font-size you need.

And then simply use this snippet:

CSS_SIZES = range(1, 7) # 1,2...6 for use in your css-file size-1, size-2, etc.

TAGS = {
    'python' : 28059,
    'html' : 19160,
    'tag-cloud' : 40,
}

MAX = max(TAGS.values()) # Needed to calculate the steps for the font-size

STEP = MAX / len(CSS_SIZES)

for tag, count in TAGS.items():
    css = count / STEP        
    print '<a href="%s" class="size-%s">%s</a>' % (tag, css, tag),

That's all. No need for a library ;-)

like image 73
zovision Avatar answered Oct 04 '22 22:10

zovision