Project 5: Word Cloud Weaver ☁️¶

Difficulty: 🟢 Beginner

Run cells top to bottom. Each step builds on the previous one and saves real files under outputs/word_cloud_weaver/.

← Back to index

Description¶

Transform any block of text into a beautiful word cloud image — great for speeches, lyrics, or journal entries.

Libraries & Modules¶

  • wordcloud.WordCloud
  • matplotlib.pyplot — display images

Python Concepts You'll Practice¶

Dictionaries, keyword arguments, displaying plots inline

🎛️ Parameter Variations¶

  • TEXT — paste your own paragraph
  • MAX_WORDS — 50 vs 200
  • COLormap — 'viridis', 'plasma', 'Set2', 'Pastel1'
  • BACKGROUND — 'white', 'black', or '#f0f0f0'
In [1]:
# Install dependencies for this project (safe to re-run)
import sys
!{sys.executable} -m pip install pillow numpy matplotlib wordcloud qrcode[pil] python-barcode fpdf2 jinja2 folium plotly pandas scipy ipywidgets -q
Skipping pip install (already installed)
In [2]:
# Interactive Jupyter setup — run this cell first
%matplotlib inline

from pathlib import Path
from IPython.display import display, Image as IPImage, HTML, Markdown, Audio, IFrame

OUTPUT_DIR = Path("outputs") / "word_cloud_weaver"
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
print(f"✅ Outputs folder: {OUTPUT_DIR.resolve()}")
✅ Outputs folder: C:\Users\Hansel Yan\Projects\CodeItAll\outputs\word_cloud_weaver

Step 1 — Prepare text and generate cloud¶

In [3]:
from wordcloud import WordCloud
import matplotlib.pyplot as plt

# 🎛️ TWEAK THESE
TEXT = '''
Python is versatile powerful readable elegant fast growing community data science web
automation machine learning scripting glue language batteries included zen beautiful
explicit simple complex hierarchy namespaces flat better than ugly sparse dense
'''
MAX_WORDS = 100
COLORMAP = "plasma"
BACKGROUND = "white"
WIDTH, HEIGHT = 900, 500

wc = WordCloud(
    width=WIDTH,
    height=HEIGHT,
    max_words=MAX_WORDS,
    colormap=COLORMAP,
    background_color=BACKGROUND,
).generate(TEXT)

out = OUTPUT_DIR / "word_cloud.png"
wc.to_file(out)
plt.figure(figsize=(12, 6))
plt.imshow(wc, interpolation="bilinear")
plt.axis("off")
plt.title("Word Cloud Weaver", fontsize=16)
plt.tight_layout()
plt.show()
print(f"Saved to {out}")
No description has been provided for this image
Saved to outputs\word_cloud_weaver\word_cloud.png

✅ Project complete¶

Check your output folder: outputs/word_cloud_weaver/

Next: Project 6: Morse Code Messenger · Index