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
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.
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 ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With