ÓÃpythonÉú³É´ÊÔÆ
PythonС°×£¬×î½üÔÚ×öÒ»¸ö´ÊÔÆ£¬ÓÐÁ½¸öÎÊÌâÏëÎÊÎÊ´ó¼Ò£¬ÔÚÕâÀïÎÒÏȱíʾ¸ÐлÀ²~~1.ͨ¹ý¡°pip install jieba¡±ÒѾÒýÈë½á°ÍÄ£¿éÁË£¬µ«ÊÇ×îÖյĴÊÔÆͼÖÐÓкܳ¤µÄ¾ä×ÓÊÇÔõô»ØÊÂѽ£¿
2.Ïë°Ñ¡°¾ØÐΡ±´ÊÔÆͼ×ö³É¡°ÖйúµØͼ¡±ÐÎ×´µÄ£¬ÇëÎÊÔõôÇôúÂëѽ£¿
¿ÉÒÔ¿´ÏÂÕâ¸ö ÎÒÃÇÀÏʦ½²´ÊÔƵݸÀý
from wordcloud import WordCloud
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from wordcloud import WordCloud, ImageColorGenerator
text = "dog cat fish bird lino tiger monkey rabbit koala panda snake"
# ¼ÓÔر³¾°Í¼
color_mask = np.array(Image.open("timg.jpg"))
wc = WordCloud(
mask=color_mask,background_color='white'
)
wc.generate(text)
image_colors = ImageColorGenerator(color_mask)
# ÔÚÖ»ÉèÖÃmaskµÄÇé¿öÏ »áµÃµ½Ò»¸öÓµÓÐͼƬÐÎ×´µÄ´ÊÔÆ axisĬÈÏΪon »á¿ªÆô±ß¿ò
plt.imshow(wc, interpolation="bilinear")
plt.axis("off")
plt.savefig("a.jpg")
˽¤Ï¤ê ·¢±íÓÚ 2021-2-24 13:16
¿ÉÒÔ¿´ÏÂÕâ¸ö ÎÒÃÇÀÏʦ½²´ÊÔƵݸÀý
import jieba
import matplotlib as mpl
import matplotlib.pyplot as plt
from wordcloud import WordCloud
from PIL import Image
#¶¨ÒåÒ»¸ö¿Õ×Ö·û´®
final = ""
#Îļþ¼ÐλÖÃ
filename = r"C:\Users\86189\ccc\wordabc.txt"
#´ò¿ªÎļþ¼Ð£¬¶ÁÈ¡ÄÚÈÝ£¬²¢½øÐзִÊ
with open(filename,'r',encoding = 'gb2312') as f:
for line in f.readlines():
word = jieba.cut(line)
for i in word:
final = final + i +" "
print(final)
word_pic = WordCloud(font_path = r"C:\\windows\\Fonts\\simhei.ttf",width = 2000,height = 1000).generate(final)
plt.imshow(word_pic)
# ÔÚÖ»ÉèÖÃmaskµÄÇé¿öÏ »áµÃµ½Ò»¸öÓµÓÐͼƬÐÎ×´µÄ´ÊÔÆ axisĬÈÏΪon »á¿ªÆô±ß¿ò
plt.imshow(word_pic, interpolation="bilinear")
plt.axis("off")
plt.savefig("c.jpg") ˽¤Ï¤ê ·¢±íÓÚ 2021-2-24 13:16
¿ÉÒÔ¿´ÏÂÕâ¸ö ÎÒÃÇÀÏʦ½²´ÊÔƵݸÀý
Ê®·Ö¸Ðл£¡¸Õ¸Õ¿´Á˺ܶà¾ÑéÌù£¬×ÜËãÍê³ÉÁË¡£µ«ÊÇÎÒ×öµÄ´ÊÔÆͼÀï³öÏֺܶ൥¸ö×ֵģ¬ÕâÖÖÇé¿öÔõô½â¾öÄØ£¿pythonÓÐûÓÐÏÞÖÆÖÁÉÙÁ½¸ö×ֵŦÄÜÄØ£¿ ±¾Ìû×îºóÓÉ Â³çêÌØÖ®Àá ÓÚ 2021-2-24 15:01 ±à¼
1 ³çêÌØÖ®Àá ·¢±íÓÚ 2021-2-24 14:57
Ê®·Ö¸Ðл£¡¸Õ¸Õ¿´Á˺ܶà¾ÑéÌù£¬×ÜËãÍê³ÉÁË¡£µ«ÊÇÎÒ×öµÄ´ÊÔÆͼÀï³öÏֺܶ൥¸ö×ֵģ¬ÕâÖÖÇé¿öÔõô½â¾öÄØ£¿ ...
²»ÖªµÀ£¬ÎÒÒ²ÊǸöÐÂÊÖ
Ò³:
[1]