파 이 썬 만으로 만 들 수 있 는 간단 한 단어 구름.
어 운 제작 에 필요 한 세 개의 가방:
: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")
효과 그림:파 이 썬 만으로 만 들 수 있 는 간단 한 단어 클 라 우 드 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 파 이 썬 제작 사 클 라 우 드 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 읽 어 보 세 요.앞으로 많은 응원 부 탁 드 리 겠 습 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Python의 None과 NULL의 차이점 상세 정보그래서 대상 = 속성 + 방법 (사실 방법도 하나의 속성, 데이터 속성과 구별되는 호출 가능한 속성 같은 속성과 방법을 가진 대상을 클래스, 즉 Classl로 분류할 수 있다.클래스는 하나의 청사진과 같아서 하나의 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.