³çêÌØÖ®Àá ·¢±íÓÚ 2021-2-24 11:32:23

ÓÃpythonÉú³É´ÊÔÆ

PythonС°×£¬×î½üÔÚ×öÒ»¸ö´ÊÔÆ£¬ÓÐÁ½¸öÎÊÌâÏëÎÊÎÊ´ó¼Ò£¬ÔÚÕâÀïÎÒÏȱíʾ¸ÐлÀ²~~
1.ͨ¹ý¡°pip install jieba¡±ÒѾ­ÒýÈë½á°ÍÄ£¿éÁË£¬µ«ÊÇ×îÖյĴÊÔÆͼÖÐÓкܳ¤µÄ¾ä×ÓÊÇÔõô»ØÊÂѽ£¿
2.Ïë°Ñ¡°¾ØÐΡ±´ÊÔÆͼ×ö³É¡°ÖйúµØͼ¡±ÐÎ×´µÄ£¬ÇëÎÊÔõôÇôúÂëѽ£¿

˽¤Ï¤ê ·¢±íÓÚ 2021-2-24 13:16:05

¿ÉÒÔ¿´ÏÂÕâ¸ö ÎÒÃÇÀÏʦ½²´ÊÔƵݸÀý
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:18:13

˽¤Ï¤ê ·¢±íÓÚ 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 14:57:37

˽¤Ï¤ê ·¢±íÓÚ 2021-2-24 13:16
¿ÉÒÔ¿´ÏÂÕâ¸ö ÎÒÃÇÀÏʦ½²´ÊÔƵݸÀý

Ê®·Ö¸Ðл£¡¸Õ¸Õ¿´Á˺ܶྭÑéÌù£¬×ÜËãÍê³ÉÁË¡£µ«ÊÇÎÒ×öµÄ´ÊÔÆͼÀï³öÏֺܶ൥¸ö×ֵģ¬ÕâÖÖÇé¿öÔõô½â¾öÄØ£¿pythonÓÐûÓÐÏÞÖÆÖÁÉÙÁ½¸ö×ֵŦÄÜÄØ£¿

³çêÌØÖ®Àá ·¢±íÓÚ 2021-2-24 15:00:14

±¾Ìû×îºóÓÉ Â³çêÌØÖ®Àá ÓÚ 2021-2-24 15:01 ±à¼­

1

˽¤Ï¤ê ·¢±íÓÚ 2021-2-25 14:10:39

³çêÌØÖ®Àá ·¢±íÓÚ 2021-2-24 14:57
Ê®·Ö¸Ðл£¡¸Õ¸Õ¿´Á˺ܶྭÑéÌù£¬×ÜËãÍê³ÉÁË¡£µ«ÊÇÎÒ×öµÄ´ÊÔÆͼÀï³öÏֺܶ൥¸ö×ֵģ¬ÕâÖÖÇé¿öÔõô½â¾öÄØ£¿ ...

²»ÖªµÀ£¬ÎÒÒ²ÊǸöÐÂÊÖ
Ò³: [1]
²é¿´ÍêÕû°æ±¾: ÓÃpythonÉú³É´ÊÔÆ