Send
Close Add comments:
(status displays here)
Got it! This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website. Note: This appears on each machine/browser from which this site is accessed.
Word clouds using Python
1. Word clouds using Python
The idea of a word cloud, or wordle, is to take some text and make the words that appear more often bigger than other words and then fit them into a colorful image.
The idea is to put more emphasis on words that appear more often and then fit them into a colorful image.
2. Example text
Consider the following text.
We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty, and the pursuit of Happiness. That to secure these rights, Governments are instituted among Men, deriving their just powers from the consent of the governed. That whenever any Form of Government becomes destructive of these ends, it is the Right of the People to alter or to abolish it, and to institute new Government, having its foundation on such principles and organizing its powers in such form, as to them shall seem most likely to effect their Safety and Happiness.
3. Text as a list
The following Python program does the following.
Creates a literal "words to omit" set.
Creates a literal "text" list.
Converts the list to text, extracts the words as a list using a regular expression, and combines the list to get text of just words.
Uses the wordcloud package to create a word cloud.
Uses the plot feature of matplotlib to create and save image.
4. Imports
5. C++ libraries
For certain installations, Python (on Windows) needs the Microsoft C++ Redistributable library.
An Internet search can help locate the exact packages to install from the Microsoft site.
The following link is useful:
https://www.scivision.co/python-windows-visual-c-14-required/ (2020-02-17)
After the installation, wordcloud installed without issues.
6. Omitted words
A word set is required for the words to omit.
7. Text list
8. Text conversion
9. Cloud create
10. Current path
Note the following.
The os.getcwd function is used to get and display the current path.
The image is saved to the current path (i.e., same folder in which the program code resides).
11. Cloud plot
12. Python program
Here is the Python code [#8]
13. Code output
Here is the output of the Python code.
14. Code image
15. Notes
There are many options for wordcloud not used here.
font changes
custom colors
16. End of page