Python (Wordcloud) implements Chinese word cloud

Source: Internet
Author: User

# 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.