Member-only story
Create Custom Word Clouds in Python
A creative way to visualize your data and send the right message to everyone

By reading this article, you’ll learn to create your own word cloud in Python. We’ll be using an easy-to-use module called wordcloud
. Based on the official documentation, this module has the following advantages:
- Filling all available space
- Being able to use arbitrary masks
- Having a simple yet efficient algorithm that can be easily modified
- Being in Python
There are five sections in this piece:
- The setup
- Basic usage
- Examples
- Command line
- Conclusion
Let’s get started.
1. The setup
You can easily install the module via pip install
. It’s highly recommended to create a virtual environment before you run the installation.
pip install wordcloud
For Anaconda users, you can install it directly from conda-forge
.
conda install -c conda-forge wordcloud
You’ll need the following dependencies as well. Kindly check if you have them installed.
- NumPy
- Pillow
- Matplotlib
Let’s move onto the next section to kick-start your project.
2. Basic Usage
First and foremost, let’s import the necessary module.
from wordcloud import WordCloud, ImageColorGenerator
import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
WordCloud
— base class to generate the word-cloud imageImageColorGenerator
— base class to recolor the words in the word-cloud image
We’ll need a few sentences of text as input for the word cloud. I’ll be using the following text as an example input for this tutorial, but feel free to use any text you prefer.
The Harry Potter series, written by J.K. Rowling, is perhaps the most popular set of novels of the modern era. With seven books and many blockbuster films to…