Word Clouds with Python.

by | Jun 15, 2021

I have been using python for a while now and have used it for a number of different projects, but this one surprised me.

Word clouds are something I have not used before. Then, I had the idea of using it for a project a while ago and struggled with finding a way to make them. Or should I say find a way that worked for that project. I had a very specific vision in mind and was struggling to make exactly what I wanted. That was until I found a python package that helps greatly with the production of word clouds.

Word_cloud is the name of the package and I have found it to be simply to use while offering great levels of customization of the final output. I used this package to make the images on this blog as testers before diving back into the initial project that got me started on this path.

Being the nerd I am I decided to use the star wars movies as inspiration after seeing one of the examples from the package doing the same thing.

A New Hope

The image above is made using the script from A New Hope and that’s it I didn’t do anything crazy to the output to show what the basic output from is while using this python package. This image was made with the code shown below to get you started. 

Empire Strikes Back

With the image above I do two major things to make the image better from the default image. I also made this image with the script from Empire Strikes Back instead of A New Hope.

  1. I used a mask to get the text to follow the shape of dath vaders helmet.
  2. I used colour manipulation to make the colour more suited to the image.

I also have put the code for this image down below for you to have a look at. 

Return of the Jedi

The final image I made was done with a mask as well. However, this time instead of just using it for the space of the image I also used it to dictate the colours for the image. The result is an image that has coloured sections that are collated to the image used. I used the script from Return of the Jedi to round out the original trilogy for this image.

The code for this final image I have also put below. 

Well I think that is enough playing around time to get back to the project at hand.

May the force be with you. 

Steven Morrison is a design innovation grad who’s part of the team here at OptimalBI, so you’ll find him squirreling away working on stuff that helps make us look good.  Connect with Steven on LinkedIn, or read some of his other blogs.

0 Comments
Submit a Comment

Your email address will not be published. Required fields are marked *