# This is a function of image processing
From Scipy.miscImport Imread
From WordcloudImport Wordcloud, Stopwords, Imagecolorgenerator
Import Matplotlib.pylabAs Plt
# parse Picture
Back_color = Imread ("./veer-141001498.png")
# Set Font path
Font ="C:\Windows\Fonts\STXINGKA. TTF "
WC = Wordcloud (Background_color="White",# background Color
max_words=500,# Maximum number of words
Mask=back_color,# Mask, generate the area of the word cloud background, the value of this parameter is plotted to draw the word cloud, when this parameter is not empty, width,height will be ignored
Max_font_size=80,# Displays the maximum value of the font
Stopwords=stopwords.add ("Bad reviews"),# Use the built-in Shield Word and add a
Font_path=font,# Solve the problem of display font garbled, can enter the c:/windows/fonts/directory to replace the font
Random_state=42,# returns a PIL color for each word
Prefer_horizontal=10)# Adjust how much font is horizontal and vertical in the word cloud
# Open Text file with etymology
Text =open (,< Span style= "COLOR: #008080" > "R" ,encoding=" Utf-8 "). Read ()
# generate word Cloud
Wc.generate (text)
# generate color value from background picture
Image_colors = Imagecolorgenerator (back_color)
# Display Picture
Plt.imshow (WC)
# Turn off axis
Plt.axis ( "off")
# paint the word cloud
Plt.figure ()
Plt.imshow (Wc.recolor ( color_func=image_colors))
Plt.axis ( "off")
# save picture
Wc.to_file ( "text2.png")
# following
Python (Wordcloud) implements Chinese word cloud