tgoop.com/CodeProgrammer/2680
Create:
Last Update:
Last Update:
Creating a word cloud based on the 'cl.txt'
file
Particularly useful for NLP tasks or social media analysis
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# Read text from a file
with open('cl.txt', 'r', encoding='utf-8') as file:
text = file.read()
# Generate word cloud
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
# Display the generated word cloud using matplotlib
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()
A word cloud is a visual representation of a list of categories/tags. The more often a word occurs, the larger the size it takes on in the cloud.
pip install wordcloud