Quick Reference · a little word cloud generator

wordcloud cheat sheet

One class does it all. Feed text (or a {word: count} dict) to a WordCloud; it counts words, drops stopwords, then lays them out with font size proportional to frequency, colours them from a colormap, and hands back an image. Learn the pipeline and the two dozen constructor knobs, and you can shape almost anything.

import / setup / CLI input & generate canvas · font · mask colour text processing output & display deprecated / gotcha most common

Distilled & cross-checked against wordcloud 1.9.x: amueller.github.io/word_cloud (API Reference + Gallery) · github.com/amueller/word_cloud · PyPI · python-course.eu · DataCamp

The pipeline — from text to a coloured image
TEXT a raw string …or a freq dict process_text tokenize · stopwords bigrams · plurals FREQUENCIES .words_ {word: count} LAYOUT font size ∝ frequency spiral pack, no overlap COLOUR colormap / color_func IMAGE to_file · to_svg imshow .generate(text) .generate_from_frequencies(d) .recolor() re-runs COLOUR only → fast
WordCloud frequency colormap mask stopwords layout collocations generate recolor to_file viridis prefer_horizontal scale contour max_words random_state

▲ the same cheat sheet, rendered the way the library would — font size by importance, colours from viridis

From text to a saved image in six lines
from wordcloud import WordCloud # the one class you needimport matplotlib.pyplot as plttext = open("speech.txt").read()wc = WordCloud(width=800, height=400, # configure in the constructor background_color="white", colormap="viridis").generate(text) # count + layout in one callwc.to_file("cloud.png") # save directly…plt.imshow(wc, interpolation="bilinear"); plt.axis("off") # …or show it
01Setup & Importonce per project
02Three Ways to Buildthe core
03Input & Frequencieswhat goes in
04Canvas & Backgroundthe frame
05Font Sizingthe core mapping
06Layout & Orientationwhere words go
07Text Processingtokenizing
08Stopwordswhat to drop
09Colour & Colormapthe palette
10Custom Colour Functionsfull control
11Masks & Shapesdraw in a shape
12Output & Exportget it out
13Display with matplotlibshow it
14Command Lineno code needed
15Recipes & Patternscopy & adapt
16Introspect & Depsunder the hood

Four ideas that decide how your cloud looks

The mechanics behind the knobs — how frequency becomes font size, why mask colours confuse everyone, the three entry points, and the three ways to colour. Based on the official wordcloud API & gallery.

font size ∝ frequency

The one rule of a word cloud. relative_scaling tunes how literally frequency maps to size.

data model code the 40×25×12× 0 · by rank relative_scaling 1 · ∝ freq

the mask rule (everyone trips here)

Words fill the non-white pixels. White (255) is masked out — the opposite of what most people expect.

the mask non-white = drawable white = out love words here only

three ways in → one cloud

Raw text, a ready-made frequency dict, or the tokenizer on its own — all converge on the same object.

.generate(text) .generate_from_frequencies .process_text → fit_words WordCloud .words_ + layout_

three ways to colour

A named colormap, your own function, or colours sampled from an image — later ones override earlier ones.

colormap wo rd "viridis" (default) color_func word one colour / rule ImageColorGenerator wo rd colours from an image

Worth memorizing

white in a mask = OUTnon-white pixels are where words may be drawn
mask overrides width/heightthe canvas takes the mask's shape
transparent PNGmode="RGBA" + background_color=None
relative_scaling0 = by rank · 1 = ∝ frequency · auto 0.5
collocations=True defaultbigrams appear; set False to avoid duplicates
color_func > colormapa colour function overrides the colormap
defaultscolormap viridis · background black
generate vs recolorrecolor() skips layout — much faster
from_frequencies ignoresstopwords, collocations & regexp don't apply
scale beats big canvasscale=2 renders large far faster
smooth displayimshow(wc, interpolation="bilinear") + axis("off")
plurals & numbersnormalize_plurals merges · include_numbers drops digits