Python makes the Chinese word cloud __python in different shapes

Source: Internet
Author: User
"" "" "" "" "" "" "" "" "" "" "" "" "Masked Wordcloud ================ Using a mask From PIL import Image import numpy as NP import Matplotlib.pyplot as PLT from Wordcloud import Wordcloud, stopwords ' this I want to get rid of the word "reply" in the data, because it belongs to impurities, directly removed will be reported coding errors, with #-*-Coding:utf-8-*-can not be resolved, so find this method, change the default encoding, do not know what the meaning of the "" Import sys reload (sys
) sys.setdefaultencoding (' Utf-8 ') # Read the whole text. #text = Open (Path.join (d, ' alice.txt ')). Read () text=open (' Fzw.txt '). Read () # Read The Mask image # taken from # http://w Ww.stencilry.org/stencils/movies/alice%20in%20wonderland/255fk.jpg alice_mask = Np.array (Image.open ("Alice_ Mask.png ")) #这里添加想要的形状, #stopwords = set (Stopwords) #stopwords. Add (" said ") ' background_color= ' white ' WC = Wordcloud (background_color= "White", max_words=2000, Mask=alice_mask, font_path= "Minisong.ttf", max_font_size=4 0,scale=0.8) #mask参数指定词云形状 # generate Word cloud # generate word Cloud mytext= ' ". Join (Jieba.cut (text)) Mytext=mytext.repl Ace (' reply', '] Wc.generate (mytext) # Store to File Wc.to_file ("Alice.png") # show Plt.imshow (WC, interpolation= ' bilinear ') plt.a
XIs ("Off") #plt. Figure () #plt. Imshow (Alice_mask, Cmap=plt.cm.gray, interpolation= ' bilinear ') #plt. Axis ("off") Plt.show () # The PiL way (if you don ' t have matplotlib) # image = Wordcloud.to_image () # image.show ()

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.