1, the preface

We have no contact with words in daily life, extract an article, analysis, processing. You can have a better understanding of this article. I don’t know. Kangkang my study notes.

2. Thesis

1. Introduction to Wordcloud library

  • Wordcloud is an excellent third-party library for wordcloud presentations.
  • Word cloud takes word display as the unit, which is a more intuitive and artistic display text.

You can see that this is a third-party library and needs to be installed.

Blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah. Is it artistic

How do you use it?

2. Installation of wordCloud library

Open the CMD command line and enter:

pip install wordcloud
Copy the code

3,Wordcloud library instructions

Yes, how do I use it?

  • The wordcloud library treats the wordcloud as a wordcloud object.
  • Wordcloud.Wordcloud() represents a text-corresponding object
  • Word clouds can be drawn based on parameters such as the frequency of word occurrences in the text.
  • Word cloud drawing shape, size, color can be set.

I may not understand the first two sentences, the last two must be known, for example, in an article, the word “like” appeared most frequently, so he showed the big. The word cloud styles shown are customizable,

4. General method of WordCloud library

w = wordcloud.wordcloud()
Copy the code
  • Based on the Wordcloud object,
  • Configure parameters, load text, output text
methods describe
w.generate(txt) Load the text TXT into the Wordcloud object W
w.to_file(filename) Output the word cloud as an image file,.png or.jpg format

So these three statements now create a word cloud

import wordcloud
w = wordcloud.wordcloud()
w.generate(txt)
w.to_file(pywordcloud.jpg)
Copy the code

So, what happens in the transition from text to word cloud

  1. Delimiter: Separate words with Spaces.
  2. Statistics: word occurrence and filtering.
  3. Font: Set the font size according to statistics
  4. Layout: color environment size.

4. Set object parameters

W = wordcloud. Wordcloud (< parameter >)Copy the code

Don’t underestimate this parameter, it contains a lot of… Similar to the main ()

parameter describe
width Refers to the width of the image generated from the word cloud object. The default is 400 pixels.
height Refers to the height of the image generated from the word cloud object. The default is 200 pixels.
min_font_size Specifies the minimum font size in the word cloud. The default is 4.
max_font_size Specifies the maximum font size in the word cloud, adjusted automatically based on highlighting.
font_stop Specifies the interval between font size progression in the word cloud. Default is 1.
font_path Specifies the font file path. Default: None.
max_words Specifies the maximum number of words to display in the word cloud. The default is 200.
stop_words Specifies a list of excluded words from the word cloud, that is, a list of words that are not displayed.
mask Specifies the word cloud shape, which defaults to a rectangle, and references the imread() function
background_ color Specifies the background color of the word cloud image, black by default.

Put these parameters directly inside:

w = wordcloud.wordcloud(width=100,heigh=50\
                       font_path=msyh.tcc)
Copy the code

conclusion

After writing this, I became familiar with the content again. Word clouds are very useful. Small analysis of a paragraph of text, large analysis of some important documents. Understand some content more intuitively through pictures. In this era of video streaming, no one should like to see a large section of text, but video, pictures. If so, clear and clear.

So that’s it, my notes.

Thank you, there are mistakes in the article, welcome your correction; My pleasure if I can be of any help to you.