WordCloud
WordCloud is a Python library for generating visual representations of text data, commonly known as word clouds or tag clouds. It takes text as input and visualizes the most frequent words, with the size of each word indicating its frequency. The library is actively maintained, with frequent updates, and focuses on efficient algorithms, flexible masking, and filling available space. The current version is 1.9.6.
Warnings
- gotcha Installation can fail if a pre-built wheel is not available for your specific Python version and operating system. This is because `wordcloud` includes some C code that requires a C compiler to build if a wheel is not found.
- breaking There have been reports of incompatibility with `matplotlib` version 3.9.0. Users might encounter issues when trying to display word clouds with this specific `matplotlib` version.
- gotcha When displaying word clouds using `matplotlib`, omitting `plt.axis('off')` will result in axes and tick marks appearing around the image, which is usually undesirable for word cloud visualizations.
- deprecated Older versions of `wordcloud` (e.g., 1.8.2.2) generated `DeprecationWarning` messages related to `Pillow`'s `textsize` function being deprecated and removed in `Pillow` 10 (July 2023).
Install
-
pip install wordcloud
Imports
- WordCloud
from wordcloud import WordCloud
Quickstart
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# Sample text data
text = "Python programming is fun. Python is great for data science. Data visualization with Python is powerful."
# Create a WordCloud object
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
# Display the generated image:
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off') # Turn off axes for a cleaner look
plt.title('My First Word Cloud')
plt.show()