Categories We Write About

Create a word cloud generator

Here’s a simple Python script to create a word cloud generator using the wordcloud library. This script will take a text input and generate a word cloud image from it.

python
from wordcloud import WordCloud import matplotlib.pyplot as plt def generate_word_cloud(text, output_file='wordcloud.png'): # Create a WordCloud object with some parameters 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') # Hide axis plt.tight_layout(pad=0) plt.show() # Save to a file wordcloud.to_file(output_file) print(f'Word cloud saved to {output_file}') # Example usage if __name__ == "__main__": sample_text = "OpenAI develops artificial intelligence technology that benefits humanity." generate_word_cloud(sample_text)

How to use:

  1. Install the required libraries if you don’t have them:

    nginx
    pip install wordcloud matplotlib
  2. Replace sample_text with your own text input.

  3. Run the script. It will display the word cloud and save it as wordcloud.png.

If you want it as a web app or with more features, just ask!

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About