Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of generating python word cloud map?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what is the method of generating python word cloud map". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

I. Online generation of word cloud pictures

1. Enter https://wordart.com/create;2. Import text keywords;3. Select the cloud shape of the word;4. Select the font. Since the default font is English, to generate Chinese fonts, you need to add fonts in C:\windows\Fonts. You can select elegant black fonts. Click Add Font to add;5. Select the direction of the text, select the direction of the text;6. Click Visualize to generate the word cloud map;7. Click Download and Share to download the picture.

II. Public opinion analysis of buyer evaluation

import pandas as pdfrom pyecharts import WordCloudwd=pd.read_csv("cp.csv",header=0)wd.head()

catename=[i[0]for i in wd[["key word"]].values]value=[int(i[0])for i in wd[["word frequency"].values]wordcloud=WordCloud(width=1200,height=600)wordcloud.add("",catename,value,word_size_range=[10,100],shape='star')

III. Text Word Cloud Map

Import text data and plot.

filename = "wang.txt"mytext = open(filename).read()mytext

from wordcloud import WordCloudmycloud = WordCloud().generate(mytext)mycloudimport matplotlib.pyplot as pltplt.rcParams <$'font.sans-serif'] =<$'SimHei']#Chinese文版mycloud = WordCloud(font_path = 'simsun. ttc', collocations=False).generate(mytext) #Solve duplicate problems %config InBacklineend.figure_format='svg'#Vector diagram display, solve unclear picture problems plt.imshow(mycloud)

plt.imshow(mycloud)plt.axis ('off ') #Remove axis plt.show()

Replace background image, code encapsulation.

from wordcloud import WordCloudimport matplotlib.pyplot as pltimport imageio

filename = "Python.txt"mytext = open(filename).read()

picture = imageio.imread('people.jpg')

mycloud = WordCloud( background_color = 'white',#background color max_words = 20000, #Maximum number of words mask = picture, #Draw word cloud with this parameter value, width and height will be ignored max_font_size = 30, #Display the maximum font size font_path = 'simsun.ttc', #Solve the problem of displaying squiggly characters collocations=False, Avoid repeating words ).generate(mytext)

plt.imshow(mycloud)

plt.axis('off')

plt.savefig('new.jpg',dpi=1000,edgecolor='blue',transparent=True, bbox_inches='tight', quality=95)plt.show()

Place this background image under the path. It is recommended to choose a solid background image.

The resulting effect is as follows:

"Python word cloud map generation method is what" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report