Don’t love zhen son love shuang son









Blog garden
Home page
New essays
contact
management
To subscribe to

Python word cloud creation method

When I first came into contact with the word cloud, I thought it was pretty, so I studied it. The official code was provided, but it was not easy for beginners to see it. Let’s have a try.

Environment: python2.7

Python library: PIL (pillow), numpy matplotlib, jieba, wordcloud PIP can be installed

File: test file Qq.txt, simulated picture QQ.jpg, font file fzybksjw.ttf (in the same directory can be)

qq.jpg

qq.txt

The view of the legend of the red corruption wood leaf family

I want to, and the bulb is being chained down to the chaos of the s, clairvoyance, in the end can only see familiar people in the future, I think mostly it is painful for thousands, even small be forgotten in the bird or being bullied as a child, can say thousands is a strong and pure children, including black ling green too, could pay for my brother, Is deeply in love with her brother, so from black ling green brother committed suicide after the incident, she actively looking for thousands help, sincere friendship gradually surfaced, forever, when it comes to thousands will say the second man, is FengShou, perhaps the first, because of the affection between them was overruled, well that's right, At the end of the day when I don't know thousands for the understanding of love, maybe just turned to do the understanding of the woman, a woman can do for a man is born a few more Eva, now want to also is really simple and rough, I don't like the inside of the men, the same also of their living is very simple that is desperate, supporting the red rot leaves home, in addition to the lonely, but why I also don't believe in him, Even pupil to save his own life's uncle disdain, since the bulb was dead, I think nobody can enter into his heart, at the same time I also felt that thousands have been watching the tears, really good yao, her love is a deviation, and if she still tube of the hair bulb, maybe her life will be change, even give her comic talent, In the end the bulb life and comic book is really interesting, why, in my opinion, boring and two full experience but can become people's support and even beautiful yearning, is her resistance, why she is so want to conquer the "central plains", but always will surrender half-brother sister boyfriend, and why she couldn't reflected in the eyes of the night, But finally make courtyard, drove even younger sister to double suicide, some sometimes really have no idea, but there is no doubt that there will be a mysterious color, to tell the truth I also don't like the bulb, because sister or tender is better, and it seems she seems to have a more ominous symbol, so that the editors whose winnowing fan is in succession, but I was filled with envy of love for her, to friends, too, Dare to correct friends and way of expression and friends say goodbye also very sacred, and for the beautiful girl's loss of a woman so soon I also produced a deep question, to the dream and life adjustment once laughed and said that his ideal and passion of life idea, I think she may be at that time that it's normal, but why the author will give her inferior change, At the end of the day or the world problems, the students collapsed, in about wool ball after brother tears disappear from the mountains become home, the eldest daughter as family support, she all of a sudden a lot of tall, is no longer driving a motorcycle to play crazy girl gangster, and then start the 12 years of comic strip, so her comic success is really is a joke or a miracle, 12 years of constant work and achieved great success, finally after the completion of cartoon, she also can have a good rest, remember she told her daughter apple of the eye "mother so tired, to rest under", if not lost eyes once glorious past, a few years old girl also won't detect mom might leave her, even if not a good and charming, Even looking at her mother's back every day, she also realized that the hairy ball in the final analysis were all dead ah, true yarn's death, die son's death, hundred night's death, each time let her life swaying up, finally collapsed... Again say thousands, from small to large, being bullied black ling green is typical, ha ha, a cried out, "pick up to the girl", a cried out, "love bully girl", after more than ten years, and still did not change, should have such a good friend, thousands of life turning point may be encountered in Chen, This fat would like than to be in vain as red rot leaves home alone, thousands of leaf like would have considered, direct let thousands into his home, in the end is it for the sake of what, mega Ye Zhen red rot leaves home can bring good fortune, but is she really did, to predict the oil crisis made early and prepared through the crisis, the problem of estimate there are many, thousands, Children is quite simple, to the last and FengShou duty forge double suicide, after she had considered her to kill FengShou, also let the apple of the eye to grandmother doubt investigate some kind of, in fact, if serious consider repeated letter, you will find the letter a is for thousands a is for the bulb, the content of the same "a mood に die ぬ" is not the same meaning, Fengshou this man is a pure man, for the boiler gave his right eye, and finally would rather die with the boiler, it can be seen that he loves this work, this cold monster, I also want to know whether he also loves Wanye, I think readers have some views, will not say, Finally have to say to the first view is telling the story of the little granddaughter, the pupil with grandmother and mother, she is an ordinary woman, I think it is absolutely right, freedom, rot in this article we see the red leaves the family's rise and fall, with the characters of die, everything is different, in the end only the pupil, loneliness, package, There are busy working father, this home lost the magic color of the past, with the passing of Wan Ye, I thought the story to the end, but why, the author to write pupil, write her love, write her outlook on life, write the world incurable... See I remembered the last ever seen an animated, named colorful, finish see I see two things, one is the sin is not to commit suicide than other SINS, because the meaning of life is very important, beyond the logic can interpret a variety of ethics, so the fear of life right, the second is that no matter how to don't lose hope in life, The world even ugly, dark again, also don't give up her, for someone is watching you, always looking after you, because there will always be the beautiful scenery in your eyes, because no matter how to not have it today, when you open your eyes to find himself still alive is not quite good, a little good enough to support you, That's why humans can see colors.Copy the code

Word.py (don’t name it wordcloud.py, try not to name it the same as the library)

#! /usr/bin/Python # -*- coding: utf-8 -*- from os import path from PIL import Image import numpy as np import matplotlib.pyplot as plt import jieba from  wordcloud import WordCloud, Dirname (__file__) # Read the whole text.file = open(path.join(d, Default_mode =jieba.cut(file) text = "". Join (default_mode) #text = text.encode('utf-8') # read the mask image # taken from # http://www.stencilry.org/stencils/movies/alice%20in%20wonderland/255fk.jpg alice_mask = np.array(Image.open(path.join(d,  "qq.jpg"))) stopwords = set(STOPWORDS) stopwords.add("said") fontname = path.join(d, 'fzybksjw.ttf ') wc = WordCloud(# set font, Font_path = fontname, background_color="white", max_words=2000, mask=alice_mask, stopwords=stopwords) # generate word cloud wc.generate(text) # store to file wc.to_file(path.join(d, "qq_result.jpg")) # show plt.imshow(wc, interpolation='bilinear') plt.axis("off") plt.figure() plt.imshow(alice_mask, cmap=plt.cm.gray, interpolation='bilinear') plt.axis("off") plt.show()Copy the code

—————– Run the word.py file

— — — — — check the results

Well, it’s still good…

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — this is the line — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

The second method of drawing word cloud map is pyecharts- HTML file

1. The first type

# -*- coding: Utf-8 -*- from __future__ import unicode_literals # test Pyecharts # #-*- Install Pyecharts $PIP from OS import  path d = path.dirname(__file__) from pyecharts import WordCloud name = ['Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications', 'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp', 'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham', 'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break'] value = [10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112, 965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265] wordcloud = WordCloud(width=1300, height=620) wordcloud.add("", name, value, word_size_range=[20, 100]) #wordcloud.show_config() #wordcloud.render(path.join(d, 'worldCloud1.html'))Copy the code

2. The second kind

# -*- coding: Utf-8 -*- from __future__ import unicode_literals # test Pyecharts # #-*- Install Pyecharts $PIP from OS import  path d = path.dirname(__file__) from pyecharts import WordCloud name = ['Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications', 'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp', 'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham', 'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break'] value = [10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112, 965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265] wordcloud = WordCloud(width=1300, height=620) wordcloud.add("", name, value, word_size_range=[30, 100], shape='diamond') wordcloud.show_config() wordcloud.render(path.join(d, 'worldCloud2.html'))Copy the code

————-

worldCloud1.html Copy the code

worldCloud2.html

 

I don't know which one my friends like, so let's try it.

Next time, I will share with you the detailed usage of Pyecharts.

(laughing)Copy the code

 

Don’t love zhen son love shuang son
The editor
collection


Refresh the comments
Refresh the page
Return to the top
The login
registered
access
More than 500,000 VC++ source: large industrial control, configuration, simulation, modeling CAD source code 2018!



[Recommendation] Join Tencent Cloud We media support plan, free domain name & server




Latest IT News



Nvidia has added filters to its games and tweeted screenshots



Intel CEO Krzanich: Data will be an endless resource to change the world



We put together a list of blockchain stocks: China Network Carrier line is up 471% in a month



Plug – in, physical, human hanging, why so fierce game plug – in?



Huawei all flash memory revenue growth in 2017 to achieve quality growth



More news…

Latest Knowledge Base articles



Step into the cloud



Threads and processes from an operating system perspective



The path to software testing transformation



Look inside and outside the door



Avenue to simple, the workplace to do things to do management



More knowledge base articles…

The announcement

Don’t love zhen son love shuang son



19 days



4



3
+ add attention

< In January 2018 >
day one two three four five six
31 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 1 2 3
4 5 6 7 8 9 10

search




Commonly used links

  • My essay
  • My comments
  • I participate in
  • The latest comments
  • My label

My label

  • python(11)
  • Flask(5)
  • php(4)
  • selenium(4)
  • sqlalchemy(3)
  • The crawler (3)
  • PhantomJS(3)
  • bs4(2)
  • Web framework (2)
  • scrapy(2)
  • More and more

Archives of essays

  • January 2018 (21)

The latest comments

  • 1. Re: common PHP functions
  • The @ grid is full but not included. Filename. Suffix, so just find the last one. With respect to ok. .
  • Don’t love Zhen Son love Shuang son
  • 2. Re: PHP common functions
  • Does obtaining a suffix require obtaining the last “.
  • — The lattice is full

Reading leaderboards

  • 1. PHP common functions (129)
  • 2. Python Climbs To Movie Heaven Horror + Games (101)
  • 3. python+bs4+urllib(38)
  • 1. Scrapy Framework1.
  • 5. Python Word Cloud creation method (33)

Review charts

  • 1. PHP common functions (2)

Recommended leaderboard

  • 1. PHP common functions (3)
  • 2. Python Word Cloud creation method (2)
  • 3. Scrapy Framework1
  • Git for Windows (1)
  • 5. Thinkphp Environment Setup (1)