Introduction:

Real strong man, will ~ suction cat suction cat!!

— — — — — — — — — — — — — — — — — –

Hello, everyone, I’m Muzi!

Some cats depend on their appearance,

Some cats rely on their alertness,

But there is such a cat, can eat by sleeping, dangdang ~ solemnly introduce to you this is my small tuanzi,

“Yes! Yes, this cat’s big name is Tuanzi, but he hasn’t got a nickname yet.”

​​

Ha ha ha ~ these two pictures were taken a long time ago! It’s fun to play with tuanzi and tickle a cat when you’re bored! The mood will also become good sa!

​​

Cat owners keep the soul of cats, cats are people.

All right! Said so many off-topic, but it is not off-topic, today xiaobian with you to do with the cat or a little relationship.

Make the cat version of the word cloud ~ is to climb the micro channel of all friends signature made oh!

The body of the

The results are 😍😍

Principle Introduction:

In fact, it is very simple, we can through the webpage version of wechat, scan code login to capture the packet crawl information, you can post to send information, you can also use the wechat interface library done by others.

LittleCoder (@Littlecoder, @Littlecoder, @Littlecoder, @Littlecoder, @Littlecoder, @Littlecoder, @Littlecoder, @Littlecoder

Environment installation:

Itchat is an open source interface for wechat personal accounts.

Jieba: is a powerful participle database that supports Chinese word segmentation.

Wordcloud: Is a library of word clouds.

PIP install itchat PIP install jieba PIP install wordCloudCopy the code

Log in wechat to get your friend’s signature.

Itchat.login () friends = itchat.get_friends(update=True)[0:] for I in friends: signature = I [" signature "] Click and drag to moveCopy the code

There is a problem here. There are a lot of span, class, emoji, emoji1F3C3, etc. These are the emoticons of personality signatures, so write a regular expression to filter out the useless information, then add each personality signature to a list and concatenate it into a string. This is what it looks like.

tList = [] for i in friends: signature = i["Signature"].replace(" ", "").replace("span", "").replace("class", "").replace("emoji", "") rep = re.compile("1f\d.+") signature = rep.sub("", Join (tList) # join(tList) # join(tList) cut_all=True) wl_space_split = " ".join(wordlist_jieba)Copy the code

Then draw word cloud map! I like cats, of course, I take cats as the first, your words are free to choose, picture material MAo.jpg.

Next, open Wordcloud in the directory to generate the image.

d = os.path.dirname(__file__)
alice_coloring = np.array(Image.open(os.path.join(d, "mao.jpg")))
Copy the code

Create word cloud object, including ‘C: \ Windows \ Fonts \ SIMLI the vera.ttf’ is the font used to generate the word cloud, for MAC need to change the font path, such as: / Users/Sebastian/Library/Fonts/Arial Unicode. The vera.ttf.

my_wordcloud = WordCloud(background_color="white", max_words=2000, mask=alice_coloring,

max_font_size=40, random_state=42,

font_path='C:\Windows\Fonts\SIMLI.TTF')\

.generate(wl_space_split)
Copy the code

According to the color of the photo, color the word cloud and display it.

image_colors = ImageColorGenerator(alice_coloring)

plt.imshow(my_wordcloud.recolor(color_func=image_colors))

plt.imshow(my_wordcloud)

plt.axis("off")

plt.show()
Copy the code

Now that the tutorial is over, let’s move on to running the process

Cough cough cough a lot of novice partners can pay attention to see the operation below ha

(1) Debug the code, after running, a TWO-DIMENSIONAL code will pop up, wechat scan login, confirm login on the mobile phone.

(2) Wait a few seconds, you can draw successfully, and pop up the Figure to show the drawing result, you can adjust the picture size and save the picture here.

Attached to the source code:

# coding: UTF-8 import itchat import re import jieba import matplotlib.pyplot as PLT from wordcloud import WordCloud, ImageColorGenerator import OS import numpy as NP import pil. Image as Image Itchat.login () friends = itchat.get_friends(update=True)[0:] tList = [] # signature = i["Signature"].replace(" ", "").replace("span", "").replace("class", "").replace("emoji", "") rep = re.compile("1f\d.+") signature = rep.sub("", Join (tList) # jieba = jieba. Cut (text, Cut_all =True) wl_space_split = "". Join (wordlist_jieba) # wordcloud Coloring = Np.array (image.open (os.path.join(d, "MAo.jpg "))) # Coloring = np.array(image.open (os.path.join(d," MAo.jpg ")) Where 'C:\Windows\Fonts\ simli. TTF' is the object that generates the word cloud. /Users/sebastian/Library/Fonts/Arial Unicode.ttf my_wordcloud = WordCloud(background_color="white", max_words=2000, mask=alice_coloring, max_font_size=40, random_state=42, Font_path ='C:\Windows\Fonts\ simli.ttf ')\.generate(wl_space_split) # Dye word cloud according to the color of the photo, Coloring = ImageColorGenerator(alice_coloring) plt.imshow(my_wordcloud.recolor(color_func=image_colors)) plt.imshow(my_wordcloud) plt.axis("off") plt.show()Copy the code

conclusion

Well, has been a lovely cat is done, we can also try other pictures of the word cloud puzzle oh – source base: #959755565# free welfare and article project source material!!

There is a small problem that you need to pay attention to. After executing the program once, the QR code will pop up frequently. Just close the program.

“Get out of the way, miss!”