Real-Time Graphing in Python Part II: Using a Word Cloud to Visualize Wikipedia Edits
Using the words from a Lorem Ipsum paragraph, I will demonstrate the simple usage of a Python Word Cloud function. You can find the whole Python Word Cloud project folder on GitHub [here]. Click on the bar below to show the code used to produce the animation in the GIF below.
The word cloud above utilizes rotation, size variation, and color mapping all using Python and a simple matplotlib annotation. There are many possibilities from here involving word clouds, and one such example using Wikipedia will be covered in the next section.
UPDATE: Newer and nicer code using spiral format below
Now that we have the word cloud generator working in conjunction with the live-plotter, we can use the Wikipedia recent changes page to test the function in real-time. The url that we need to crawl in order to view recent changes is:
In order to crawl the above page, I use the following Python method that gets webpage information via the requests library:
The above code will crawl Wikipedia's recent changes page for edits made by users and return the title of each page edited.
If everything looks good, we now want to take those titles and create a dynamic word cloud. We can do so by combining the Wikipedia page crawl and the word cloud above and use a while-loop to incorporate Wiki edit titles on the recent changes page. The word cloud result should look similar to the .gif below:
The full code used to create the dynamic word cloud can be found below (click to expand):
In this tutorial I demonstrated how to create a live word cloud using Python. As an example, I first scattered a Lorem Ipsum paragraph around a matplotlib figure to create a simple word cloud with words that vary in size, color, and rotation angle. Then, I used a real-world example that showed the user how to crawl Wikipedia's recent changes page and plot each Wiki title to a dynamic word cloud casting each recent change onto a figure full of multi-colored words. Using these examples and the code above, the user is capable of creating their own word cloud using any series of words or titles.
See More in Live Plotting and Python: