In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to draw a word cloud map in Python. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
In Python, we can use pyecharts to do word cloud map, or we can use matplotlib to draw word cloud map, and the word cloud map drawn by matplotlib is more personalized.
Materials: TXT files, jupyter notebook, PPT, computer, jieba thesaurus in Python, wordclound library, matplotlib library, Wechat screenshots or other tools, etc.
Data structure:
# Import related library import jiebafrom wordcloud import WordCloudimport matplotlib.pyplot as plt# imports text data and performs simple text processing. Note that the text is encoded as text = open, such as gbk or utf-8 (r "C:\ Users\ QDM\ Desktop\ SAP out price\ 9-07\ ciyun.txt", encoding = "gbk"). Read () # remove the newline character and space text = text.replace ('\ npermission, "). Replace ("\ u3000 ",") # preview the loaded content text
# participle, returns a list of words text_cut = jieba.lcut (text) # splits the divided word with a symbol and concatenates it into the string text_cut = '.join (text_cut)
# Import stop words # used to remove text similar to'ah 'and' you' Words like'I 'stop_words = open (r "C:\ Users\ QDM\ Desktop\ SAP out price\ 9-07\ ciyun.txt", encoding = "gbk") .read () .split ("\ n") # use WordCloud to generate the word word _ cloud = WordCloud (font_path= "simsun.ttc", # set the word cloud font background_color= "white" # background color of the word cloud image stopwords=stop_words) # removed stop word word_cloud.generate (text_cut) # render the word cloud image with matplotlib # adjust the length and width of the canvas plt.subplots (figsize= (12Power8)) plt.imshow (word_cloud) plt.axis ("off")
Render effect:
Next, we can customize the shape of the word cloud we want according to our own ideas. As follows:
We can now set the following effects in PPT:
Then cut and save the screenshot with Wechat or other tools.
Write the complete code:
# complete code # Import the relevant library import jiebafrom wordcloud import WordCloudimport matplotlib.pyplot as pltfrom PIL import Image# to load and process the participle text = open (r "C:\ Users\ QDM\ Desktop\ SAP outgoing price\ 9-07\ ciyun.txt", encoding = "gbk"). Read () text = text.replace ('\ npermission, "). Replace ("\ u3000 ") "") text_cut = jieba.lcut (text) text_cut =''.join (text_cut) stop_words = open (r "C:\ Users\ QDM\ Desktop\ SAP out price\ 9-07\ ciyun.txt", encoding = "gbk"). Read (). Split ("\ n") # read the background picture You can also enter background = Image.open (r "C:\ Users\ QDM\ Desktop\ fu.png") graph = np.array (background) word_cloud = WordCloud (font_path= "simsun.ttc", background_color= "white", mask=graph) # specify the shape of the cloud stopwords=stop_words) # render effect word_cloud.generate (text_cut) plt.subplots (figsize= (12Magazine 8)) plt.imshow (word_cloud) plt.axis ("off")
The rendered effect:
The above content is how to draw word cloud map in Python. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.