requirements:

see a circle of friends to send a word cloud photos, feel that they can play a play, so the use of wordcloud to achieve the function.

MacOS 10.12 +Python 2.7 environment:

+Wordcloud
Windows

: general to install wordcloud

 install wordcloud 

SIP $PIP function is the system integrity protection function of Apple in OSX on the launch of the new version of the macOS, the direct use of PIP installation error, without closing the SIP function, you can use

PIP install wordcloud --user -U

 $

will prompt some mistakes, you need to install the VS for Python, directly on the official website to download and install.

 source: /usr/bin/env Python import # #! From OS import path from PIL import Image import numpy as NP import matplotlib.pyplot as PLT from wordcloud import WordCloud, STOPWORDS current # path d = path.dirname (__file__) Read the whole text. text # (path.join = open (D,'test.txt') (.Read) read the mask image test_mask #) = np.array (Image.open (path.join (D, test_mask.png) stopwords)) = set (STOPWORDS) stopwords.add ("said") # setting WC = WordCloud (background_color= black, max_words=2000, mask=test_mask, stopwords=stopwords) # generate word cloud wc.generate (text) plot and show plt.imshow # (WC, interpolation='bilinear') plt.axis (off) plt.figure (plt.imshow (test_mask, cmap=plt.) Cm.gray, interpolation='bilinear') plt.axis (off) plt.show (store) # to file wc.to_file (path.join (D, test.png)) 

test_mask.png

></p>
<p>

test.txt

The list of big's prior run-ins with the far-right fringe is long and varied. He tweeted fake crime statistics spread by racists to paint black cans as violent, then defended them as credible. He sparked a firestorm last year when he declined to renounce

here to write the picture description

, other instructions:

1. document can be any TXT file in English, the above is a short paragraph in the English news on the Internet, it only plays an exemplary role.
2. on Chinese support, there are a variety of methods, mainly the problem of word segmentation, this is not discussed here.
3., I don't know what many people call customization, because if I want to shape myself, I think using PS to make a PNG diagram can achieve the same effect.
4. wrote the first article, the inadequacies of welcome to spray, after all, I am to learn.

is the whole content of this article, I hope to help you, and hope that you can support a lot of scripting home.


This concludes the body part