The word cloud is also called the text cloud, is to appear the high frequency in the text data "The key word" in the visual prominent present, forms the keyword the rendering to resemble the cloud similar color picture, thus one eye can appreciate the text data the main expression meaning.
It is complicated to generate your own word cloud with code. It will take a long time. Many of the text has been introduced in a variety of ways, but in fact it only takes 10 lines of Python code.
Import Matplotlib.pyplot as PLT from
wordcloud import wordcloud
import Jieba
text_from_file_with_apath= Open (' 20180118.txt '). Read ()
Wordlist_after_jieba = Jieba.cut (text_from_file_with_apath, cut_all = True)
Wl_ Space_split = "". Join (Wordlist_after_jieba)
My_wordcloud = Wordcloud (font_path= './fonts/simhei.ttf '). Generate ( Wl_space_split)
plt.imshow (My_wordcloud)
Plt.axis ("Off")
Plt.show ()
So, generate a word cloud:
Take a look at these 10 lines of code:
The 1~3 line is imported into the drawing library, the word cloud generates the library and the Jieba's word base;
4 lines are read local files, the text used in the code.
5~6 line using Jieba for participle, and the result of participle separated by space;
7 lines to the text generated after the word cloud, 8~10 line with pyplot display word clouds
The key to the Chinese problem of the word cloud is to add in the Wordcloud:
Font_path= './fonts/simhei.ttf '