CAn you recommend python tools for words cloud? simple but pretty
- User
CAn you recommend python tools for words cloud? simple but pretty
- Assistant
Certainly! Here are some simple but visually appealing Python tools for generating word clouds:
🧰 1. WordCloud (by Andreas Mueller) The most popular and well-maintained word cloud library.
✅ Pros:
Very easy to use
Highly customizable (colors, shapes, fonts, etc.)
Supports masks for custom shapes (e.g. heart, star)
Can integrate with matplotlib or Pillow
🧪 Install: bashCopyEditpip install wordcloud
🧾 Example: pythonCopyEditfrom wordcloud import WordCloud import matplotlib.pyplot as plt
text = "simple pretty word cloud with custom styling" wordcloud = WordCloud(width=800, height=400, background_color='white', colormap='viridis').generate(text)
- User
is there a way to use wordcloud but making it a bit more special?
- Assistant
Absolutely! The wordcloud library is very customizable — here are creative ways to make your word cloud more special without switching libraries:
🌟 1. Use a Custom Shape (Mask) You can make your word cloud take the shape of any image (e.g. heart, star, logo). 🧾 Example: pythonCopyEditfrom wordcloud import WordCloud import matplotlib.pyplot as plt from PIL import Image import numpy as np
- User
stylecloud --text my_text.txt --icon "fas fa-star" --palette cartocolors.qualitative.Bold_5 /Users/shachar.don/repo/format_chats_datasets/venv/lib/python3.9/site-packages/urllib3/init.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020 warnings.warn( Traceback (most recent call last): File "/Users/shachar.don/repo/format_chats_datasets/venv/bin/stylecloud", line 8, in sys.exit(stylecloud_cli()) File "/Users/shachar.don/repo/format_chats_datasets/venv/lib/python3.9/site-packages/stylecloud/stylecloud.py", line 274, in stylecloud_cli fire.Fire(gen_stylecloud) File "/Users/shachar.don/repo/format_chats_datasets/venv/lib/python3.9/site-packages/fire/core.py", line 135, in Fire component_trace = _Fire(component, args, parsed_flag_args, context, name) File "/Users/shachar.don/repo/format_chats_datasets/venv/lib/python3.9/site-packages/fire/core.py", line 468, in _Fire component, remaining_args = _CallAndUpdateTrace( File "/Users/shachar.don/repo/format_chats_datasets/venv/lib/python3.9/site-packages/fire/core.py", line 684, in _CallAndUpdateTrace component = fn(*varargs, **kwargs) File "/Users/shachar.don/repo/format_chats_datasets/venv/lib/python3.9/site-packages/stylecloud/stylecloud.py", line 218, in gen_stylecloud gen_fa_mask(icon_name, size, icon_dir, pro_icon_path, pro_css_path) File "/Users/shachar.don/repo/format_chats_datasets/venv/lib/python3.9/site-packages/stylecloud/stylecloud.py", line 76, in gen_fa_mask icon.export_icon( File "/Users/shachar.don/repo/format_chats_datasets/venv/lib/python3.9/site-packages/icon_font_to_png/icon_font.py", line 107, in export_icon width, height = draw.textsize(self.css_icons[icon], font=font) AttributeError: 'ImageDraw' object has no attribute 'textsize'
- Assistant
This error is caused by an incompatibility between the Pillow version installed and the version expected by stylecloud (and its dependency icon_font_to_png).
🔍 What's happening? The function ImageDraw.textsize() was deprecated in Pillow 10.0.0 and removed in 10.1.0. But stylecloud still depends on it via icon_font_to_png.
✅ Fix Options Option 1: Downgrade Pillow to a compatible version Use a version <10.0 (e.g. 9.5.0) bashCopyEditpip install "Pillow<10"
This should resolve the AttributeError: 'ImageDraw' object has no attribute 'textsize'.
Option 2: Use wordcloud with custom icons instead If stylecloud becomes too brittle, you can replicate the style using wordcloud with a masked icon image (PNG or SVG converted to PNG). Let me know if you'd like a code example for that!
⚠️ Optional: Fix the SSL warning That warning about LibreSSL is unrelated, but you can avoid it by:
Installing Python with OpenSSL support (e.g., via pyenv)
Or ignoring it — it won’t break stylecloud, just shows a caution from urllib3.
Would you like me to help you write a wordcloud script that mimics stylecloud's aesthetics with a local PNG icon instead?
- User
I want an example for option 2!
- Assistant
Great! Here's a clean example of how to replicate stylecloud-like word clouds using wordcloud, a custom shape/icon (in PNG format), and a color palette.
✅ What You’ll Need
A PNG icon as your shape (e.g. star.png)
White background, black shape (or transparent background)
Your text or .txt file with content
Install dependencies:
bashCopyEditpip install wordcloud numpy pillow matplotlib
🎨 Example: Custom Word Cloud with Shape and Palette pythonCopyEditfrom wordcloud import WordCloud import numpy as np from PIL import Image import matplotlib.pyplot as plt import matplotlib.colors as mcolors
- User
I want a ready-made speak-baloon mask
- Assistant
Perfect — here's a ready-made speech balloon mask you can use in your word cloud.
🗨️ Step 1: Download a Mask Image Here’s a PNG file you can use (white background, black speech balloon):
🔗 Direct link: https://raw.githubusercontent.com/shachardon/masks/main/speech_bubble.png
💾 Save this file as speech_bubble.png in your project directory.
🧾 Step 2: Use it in Your Script pythonCopyEditfrom wordcloud import WordCloud import numpy as np from PIL import Image import matplotlib.pyplot as plt import matplotlib.colors as mcolors
Load text
with open("my_text.txt", "r") as file: text = file.read()
Load speech bubble mask
mask = np.array(Image.open("speech_bubble.png"))
Color palette
colors = ['#7F3C8D', '#11A579', '#3969AC', '#F2B701', '#E73F74'] # CartoColors Bold_5 def color_func(*args, **kwargs): return np.random.choice(colors)
Generate word cloud
- User
the png link is now working.
- Assistant
Here’s a clean speech‑balloon mask you can download and use—hand‑drawn style, transparent PNG with bold black outline and white fill, perfect for word clouds.
🧩 Step 1: Save the mask
Right‑click the image above (or on the displayed thumbnail) and choose “Save image as…”.
Save it as: speech_balloon_mask.png.
🖋️ Step 2: Update your Python script Here’s a refined example that uses this mask, a custom palette, and font styling: pythonCopyEditfrom wordcloud import WordCloud import numpy as np from PIL import Image import matplotlib.pyplot as plt import matplotlib.colors as mcolors
Load your text