본문 바로가기

기초언어

(92)
WordCloud Font HSL Color Code 1>from wordcloud import WordCloud from matplotlib import pyplot def make_colors(word, font_size, position, orientation, random_state, **kwargs): color = "hsl Color Code" return color text = '' with open("파일경로", encoding="utf-8") as f: text = f.read() wc = WordCloud(width=1200, height=800, scale=2.0, max_font_size=150, background_color="#ffffff") gen = wc.generate(text) recolor = gen.recolor..
WordCloud Font RGB Color Code 1>from wordcloud import WordCloud from matplotlib import pyplot def make_colors(word, font_size, position, orientation, random_state, **kwargs): color = "rgb(0, 0, 0)" return color text = '' with open("파일경로명", encoding="utf-8") as f: text = f.read() wc = WordCloud(width=1200, height=800, scale=2.0, max_font_size=150, background_color="#ffffff") gen = wc.generate(text) recolor = gen.recolor(..
WordCloud Font Single Hex Color Code>from wordcloud import WordCloud from matplotlib import pyplot def make_colors(word, font_size, position, orientation, random_state, **kwargs): color = "Hex Color Code" return color text = '' with open("파일경로", encoding="utf-8") as f: text = f.read() wc = WordCloud(width=1200, height=800, scale=2.0, max_font_size=150, background_color="#ffffff") gen = wc.generate(text) recolor = gen.recolor(c..
WordCloud Option Background image Code>from PIL import Image import numpy img = Image.open("배경화면경로"); img_array = numpy.array(img) wc = WordCloud(width=600, height=1200, max_font_size=150, scale=2.0, max_words=100, stopwords=ignore, mask=img_array)White Background Code>background_color="white" 정리>Numpy 모듈이 적용된 이미지를 로드하여 배열로 변환 한뒤 사용한다.보통 배경 이미지를 가져와서 출력을 할려면 배경은 흰색 해당 그림은 검은색이 적용된 이미지를 가져와야된다.투명도가 지정된 이미지는 출력이 정상적으로 이루어지지 않는다.또한..
WordCloud Option Forbidden word Code>from wordcloud import STOPWORDS ignore = set(STOPWORDS) ignore.add("금지어") 정리>WordCloud 모듈의 STOPWORDS를 사용하여 금지어를 설정할수 있다.빈도수를 계산할때 제외되는 단어라고 생각하면 된다.STOPWORDS의 Type는 set이다.ignore.add를 추가로 작성하여 금지어를 여러개 설정할 수 있다.
WordCloud Basic Code>from wordcloud import WordCloud from matplotlib import pyplot text = '' with open("파일경로", encoding="utf-8") as f: text = f.read() wc = WordCloud(width=1200, height=800, scale=3.0) gen = wc.generate(text) pyplot.figure() pyplot.imshow(gen, interpolation='bilinear') wc.to_file("출력파일명") pyplot.close() 정리>4 ~ 6 : 텍스트 파일 읽어 들여 text 변수에 담아 읽어들인다. 파일경로에 자기가 만들 파일의 원본의 주소를 입력한다. 8 : WordCloud 객체 결과..
WordCloud Module Import Code>from wordcloud import WordCloud from matplotlib import pyplot 정리>import 모듈from 모듈 import 모듈함수 현재 디렉토리에 있는 파일이나 파이썬 라이브러리 모듈을 불러들여서 사용한다. wordcloud / matplotlib 는 pipinstall로 설치해서 사용이 가능하다. 워드클라우드 / 그래프 모듈을 불러들여서 사용한다.
Koera Constitution WordCloud Python Code>from wordcloud import WordCloud from matplotlib import pyplot from collections import Counter from konlpy.tag import Okt from PIL import Image import numpy text = '' with open('데이터위치', encoding="utf-8") as f: text = f.read(); nlp = Okt() nouns = nlp.nouns(text) words = [] for n in nouns: if len(n) > 1: words.append(n) count = Counter(words) most = count.most_common(100) tags = {} for..