Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the method of generating python word cloud map?

Shulou Source: shulou.com Published: 2022-06-01 04:12:58 09月10日 Update

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!

Tags: Cloud image generation font selection background picture text problem method maximum key keyword content text direction more knowledge Chinese successful learning next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Docker Huawei OPPO Reno vpn