Intro
For about five years now, I’ve been saving my favorite song verses into a CSV file, along with a “score” of how much I like it. After some time, I decided to do a wordcloud in Mathematica but, after finding the WordCloud python package, I decided to translate it into Python and enhance it a bit. With over 885 verses, this script generates a wordcloud with all the verses and makes it easy to overlay it over a background with software such as Adobe Illustrator.
CodeDev
As previously mentioned, verses are stored in a CSV with each row consisting of a verse-score tuple. This score is somewhat arbitrary and unbounded, but it does provide a certain metric that will be used to define the sizes of the verses in the cloud.
Setup variables
First thing we’ll do is to import the required libraries:
And our working directories:
With those out of the way, we’ll define some image resolution and style parameters:
Load data
With these parameters defined, we load our CSV file into a pandas dataframe.
Generate wordcloud
To make it look better, I decided to use a typewriter-like font I downloaded from: 1001 freefonts. The lines that define and generate the wordcloud follow:
Save image
And then we save it to disk using matplotlib without a frame or padding:
Overlaying
It is worth noting that these lines create a wordcloud without a background, but by using Inkscape with one of the watercolor paper backgrounds downloaded from inspiration hut, it is extremely easy to combine the layers to produce the final result:
Code repo
- Repository: Github repo
- Dependencies: matplotlib, WordCloud, pandas