파 이 썬 만으로 만 들 수 있 는 간단 한 단어 구름.

준비 하 다
어 운 제작 에 필요 한 세 개의 가방:

  :pip install matplotlib
  :pip install jieba
  :pip install wordcloud
(다른 가방 이 필요 할 수 있 습 니 다:pip install numpy 등 자체 적 으로 추가 할 수 있 습 니 다)
영어
test.txt 텍스트 내용:

python python3 is good well bestbast shell cool
Age has reached the end of the beginning of a word. May be guilty in his seems to passing a lot of different life became the appearance of the 
same day; May be backto oneself the paranoid weird belief disillusionment, these days, my mind has been very messy, in my mind constantly. Always 
feel oneself should go to do something, or write something. Twenty years of life trajectory deeply shallow, suddenly feel something, do it.The end 
of our life, and can meet many things really do?During myhood, think lucky money and new clothes are necessary for New Year, but as the advance of 
the age, will be more and more found that those things are optional; Junior high school, thought to have a crush on just means that the real growth,
but over the past three years later, his writing of alumni in peace, suddenly found that isn't really grow up, it seems is not so important; Then 
in high school, think don't want to give vent to out your inner voice can be in the high school children of the feelings in a period, but was event
ually infarction when graduation party in the throat, later again stood on the pitch he has sweat profusely, looked at his thrown a basketball hoops
, suddenly found himself has already can't remember his appearance.
원본 코드:

import matplotlib.pyplot as plt  #        ,      figure  ,                   
import jieba  # jieba           (                 )
from wordcloud import WordCloud  #   wordcloud 

text = open(r'test.txt', "r").read()  #   txt    ,          r R         ,                ,   r  “  ”
cut_text = jieba.cut(text)  #       ,     ,      ,       ,             
result = " ".join(cut_text)  #                    ,        
# join     :'sep'.join(seq)    :sep:   。    ;seq:        、   、  、  ; : sep     , seq               

#      ,        WordCloud       ,              
#        :              ,         ,      :mode='RGBA' colormap='pink'
wc = WordCloud(
    #     ,         
    background_color='white',  #      ,     
    width=500,  #      
    height=350,  #      
    max_font_size=50,  #     
    min_font_size=10,  #     
    mode='RGBA'  #     “RGBA”  background_color    ,     
)
wc.generate(result)  #             
wc.to_file(r"wordcloud.png")  #          
plt.imshow(wc)  #           
plt.axis("off")  #        ,       
plt.show()  # plt.imshow()           ,      ,      。     plt.show()    
효과 표시:
在这里插入图片描述
중국어
pkq.jpg 템 플 릿 내용:
在这里插入图片描述
poem.txt 텍스트 내용:

          ,       。
          ,       。
       ,       。
       ,       。
       ,       。
   ,   ,   ,   。
     ,       。
       ,       。
       ,       。
       ,       。
       ,       。
   ,   ,
       ,       。
     ,     。
     ,     。
     ,       。
     ,       。
       ,       。
       ,       。
       ,       。
     ,     。
       ,       。
     ,     。
     ,     。
       ,       。
       ,       。
      ,      。
    ,    。    ,    。
       ,       。
       ,         。
       ,       。
      ,      。
      ,      。
       ,       。
       ,       ,
       。         ,
       
원본 코드:

import wordcloud
import numpy as np
from PIL import Image # Image    Python PIL         
import jieba

pic = Image.open("pkq.jpg")  #       ,    
shape = np.array(pic)  #          
wc = wordcloud.WordCloud(mask=shape, font_path="simkai.ttf", background_color="white",
                         max_font_size=100)  # mask     ,font_path   ,        

text = open(r'poem.txt', "r", encoding='UTF-8').read()  #             utf―8
cut_text = jieba.cut(text)
result = " ".join(cut_text)
wc.generate(result)
wc.to_file("cloud.jpg")
효과 그림:
在这里插入图片描述
파 이 썬 만으로 만 들 수 있 는 간단 한 단어 클 라 우 드 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 파 이 썬 제작 사 클 라 우 드 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 읽 어 보 세 요.앞으로 많은 응원 부 탁 드 리 겠 습 니 다!

좋은 웹페이지 즐겨찾기