import numpy as np
from PIL import Image # converting images into arrays
import matplotlib as mpl
import matplotlib.pyplot as plt
# import package and its set of stopwords
from wordcloud import WordCloud, STOPWORDS
# remove stopwords
stopwords = set(STOPWORDS)
# we can add any word that we don't want visualize
stopwords.add('word')
# open the file and read it into a variable
words = open('words.txt', 'r').read()
# instantiate a word cloud object
new_wc = WordCloud(
background_color='white',
max_words=2000,
stopwords=stopwords
)
# generate the word cloud
new_wc.generate(words)
# display the word cloud
plt.imshow(new_wc, interpolation='bilinear')
plt.axis('off')
plt.show()
# we can resize it
fig = plt.figure()
fig.set_figwidth(14) # set width
fig.set_figheight(18) # set height
# display the cloud
plt.imshow(new_wc, interpolation='bilinear')
plt.axis('off')
plt.show()
# We can use an image as background instead the rectangle when instantiate the object
new_img = np.array(Image.open('image.png'))
new_wc = WordCloud(
background_color='white',
max_words=2000,
mask=new_img,
stopwords=stopwords
)
Categories
Bash
(3)
BOT
(2)
C#
(1)
Cluster Analysis
(1)
Data Cleaning
(6)
Data Ingestion
(2)
Data Science Specialization
(10)
Data Visualization
(15)
ggplot2
(1)
Hadoop
(1)
Hashnode
(3)
Machine Learning
(5)
MapReduce
(1)
Maps
(1)
Markdown
(7)
Market Basket Analysis
(1)
MATLAB
(1)
Matplotlib
(3)
Numpy
(2)
Octave
(1)
Pandas
(3)
Python
(17)
R
(22)
Regression
(7)
scikit-learn
(1)
Seaborn
(1)
Shell
(3)
Shiny App
(1)
SSIS
(3)
Statistical Inference
(2)
T-SQL
(8)
Unix
(3)
No comments:
Post a Comment