Blog Detail

preview image Programming
by Anurag Srivastava, Jun 30, 2018, 6:06:45 AM | 2 minutes

Create word cloud in Python

In this blog we are going to learn word cloud creation in Python. There are some really good libraries available in Python using which we can create different types of word clouds.

We can use these words clouds to display them on websites or can print them to use on your desk. So sets start the word cloud creation by installing the wordcloud library. We can install it using pip:

sudo pip3 install wordcloud

Once wordcloud library is installed we can use it in our Python script for creating the word cloud. We also need matplotlib library fro creating the word plot. So please install matplotlib in case it is not installed.

Before creating the Python script we can create a text file to write all the words which we are going to display in word cloud. So create a file named const.txt and add each words line by line:


Now start creating the Python script by importing os, wordcount and matplotlib library:

from os import path
from wordcloud import WordCloud
import matplotlib.pyplot as plt

Now get the current directory and read the const.txt file:

d = path.dirname(__file__)
text = open(path.join(d, 'const.txt')).read()

Now create the word cloud:

wordcloud = WordCloud().generate(text)

Use matplotlib to display the generated image of word cloud:

plt.imshow(wordcloud, interpolation='bilinear')
# this will remove the axis display along with the image.

We can also pass additional parameters to WordCloud() method like max font size etc.

wordcloud = WordCloud(max_font_size=40).generate(text)

In this way we can create the word cloud. You can refer to word cloud library for more options. In case of any query please leave the comment.

About Author

Anurag Srivastava

Author | Blogger | Tech Lead | Elastic Stack | Innovator |

View Profile

Comments (0)

Leave a comment

Related Blogs

Basics of Data Search in Elasticsearch

Aug 4, 2018, 7:02:21 AM | Anurag Srivastava

Elasticsearch Rest API

Jul 31, 2018, 6:16:42 PM | Anurag Srivastava

Bucket Aggregation in Elasticsearch

Aug 29, 2018, 7:15:06 PM | Anurag Srivastava

Wildcard and Boolean Search in Elasticsearch

Aug 10, 2018, 7:14:40 PM | Anurag Srivastava

Metrics Aggregation in Elasticsearch

Aug 18, 2018, 6:02:20 PM | Anurag Srivastava

Introduction to Elasticsearch Aggregations

Aug 14, 2018, 4:47:56 PM | Anurag Srivastava

Create a Pie Chart in Kibana

Dec 24, 2018, 5:25:28 PM | Anurag Srivastava

Typecasting in PHP for short datatype

Jun 8, 2018, 8:03:52 AM | Lovish Sharma

Top Blogs

Configure SonarQube Scanner with Jenkins

Jun 21, 2018, 4:58:11 AM | Anurag Srivastava

Build and deploy Angular code using Python

Jun 26, 2018, 4:50:18 PM | Anurag Srivastava

Configure Jenkins for Automated Code Deployment

Jun 13, 2018, 3:44:01 PM | Anurag Srivastava

SonarQube installation on Ubuntu

May 12, 2018, 4:47:07 PM | Anurag Srivastava

Execute Commands on Remote Machines using sshpass

Jul 16, 2018, 5:00:02 PM | Anurag Srivastava

Why SonarQube is important for IT projects ?

Apr 24, 2018, 2:52:28 PM | Anurag Srivastava

Analyze your project with SonarQube

Jun 2, 2018, 10:49:54 AM | Anurag Srivastava

Install Jenkins on Ubuntu

May 26, 2018, 6:42:02 PM | Anurag Srivastava

Install Kafka on Ubuntu

Jul 12, 2018, 7:40:51 PM | Anurag Srivastava

Log analysis with Elastic stack

Jan 31, 2018, 6:11:29 AM | Anurag Srivastava