Creating Word Cloud in Python --- Making Words Different Sizes?
Question: I am trying to create a word cloud in python using
[pytagcloud](https://pypi.python.org/pypi/pytagcloud/). With my current cloud,
I can generate a cloud, but the words all are the same size. How can I alter
the code so that my words' sizes appear in relation to their frequency?

My text file already has the words with their respective frequency counts
already in it, the format is like "George, 44" newline "Harold, 77", newline,
"Andrew, 22", newline, etc. However, when it displays the word, it also
displays the frequency with it.

    
    
    with open ("MyText.txt", "r") as file:
       Data =file.read().replace('\n', '')
    
    tags = make_tags(get_tag_counts(Data), maxsize=150)
    
    create_tag_image(tags, 'Sample.png', size=(1200, 1200),background=(0, 0, 0, 255),  fontname='Lobstero', rectangular=True)
    
    import webbrowser
    webbrowser.open('Sample.png')
    


Answer: You need to cast the result into a tuple. Using your question as input text we
get the expected result:

    
    
    from pytagcloud import create_tag_image, make_tags
    from pytagcloud.lang.counter import get_tag_counts
    
    TEXT = '''I am trying to create a word cloud in python. With my current cloud, I can generate a cloud, but the words all are the same size. How can I alter the code so that my words' sizes appear in relation to their frequency?'''
    
    counts = get_tag_counts(TEXT)
    tags = make_tags(counts, maxsize=120)
    create_tag_image(tags, 'cloud_large.png', size=(900, 600), fontname='Lobster')
    

![enter image description here](http://i.stack.imgur.com/nlaGG.png)

It is worth looking at the variable `counts`:

    
    
    [('cloud', 3), 
    ('words', 2), 
    ('code', 1), 
    ('word', 1), 
    ('appear', 1), ...
    

which is simply a list of tuples. Since your input text file contains a list
of tuples, you simply need to pass that information into `make_tags`.

**Edit:** You can read a file like this

    
    
    counts = []
    with open("tag_file.txt") as FIN:
       for line in FIN:
           # Assume lines look like: word, number
           word,n = line.strip().split()
           word = word.replace(',','')
           counts.append([word,int(n)])
    

