Better Programming

Advice for programmers.

Follow publication

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:

  1. The setup
  2. Basic usage
  3. Examples
  4. Command line
  5. 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 image
  • ImageColorGenerator — 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…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Ng Wai Foong
Ng Wai Foong

Written by Ng Wai Foong

Senior AI Engineer@Yoozoo | Content Writer #NLP #datascience #programming #machinelearning | Linkedin: https://www.linkedin.com/in/wai-foong-ng-694619185/

No responses yet

Write a response