
seaborn์ ํ์ด์ฌ์ ๋ฐ์ดํฐ ์๊ฐํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋๋ค. ์ด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์๋ คํ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
sns.lineplot(x=[1, 3, 2, 4], y=[4, 3, 2, 1])
์์ ๋ช
๋ น์ด๋ฅผ ์์ฑํ๋ฉด ๋ฐ์ ๊ทธ๋ํ๊ฐ ๋์ต๋๋ค.

sns.barplot(x=[1,2,3,4],y=[0.7,0.2,0.1,0.05])

seaborn์ ํ์ด์ฌ์ ์๊ฐํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ matplotlib์ ๊ธฐ๋ฐ์ผ๋ก ๋ง๋ค์ด์ก์ต๋๋ค.
matplotlib.pyplot์ ์์ฑ์ ๋ณ๊ฒฝํด์ ๊ทธ๋ํ์ ๋ค์ํ ์์๋ฅผ ๋ณ๊ฒฝ/์ถ๊ฐํ ์ ์์ต๋๋ค.
import matplotlib.pyplot as plt
#plt.figure(figsize = (x, y)) : ๊ทธ๋ํ์ ํฌ๊ธฐ ๋ฅผ ์ง์ ํฉ๋๋ค.
plt.figure(figsize = (20,10))# ์์๋ค ์ ์ด์ค์ผ๋จ
# plt.title() : ๊ทธ๋ํ์ ์ ๋ชฉ ์ ์ถ๊ฐํฉ๋๋ค
sns.barplot(x=[1,2,3,4],y=[0.7,0.2,0.1,0.05])
plt.title("Bar Plot")
# plt._label() : ๊ทธ๋ํ์ ์ถ์ ์ค๋ช
์ ์ถ๊ฐํฉ๋๋ค
plt.xlabel("this is x-label")
plt.ylabel("this is y-label")
#plt._lim() : ๊ทธ๋ํ์ ์ถ์ ๋ฒ์ ๋ฅผ ์ง์ ํฉ๋๋ค.
plt.ylim(2,3)
wordcloud ๋ผ์ด๋ธ๋ฌ๋ฆฌ
wordcloud๋ ํ์ด์ฌ์ ํ ์คํธ ํด๋ผ์ฐ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋๋ค. ์ด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ ์คํธ ๊ตฌ๋ฆ์ ๊ทธ๋ฆด ์ ์์ต๋๋ค. konlpy๋ ํ๊ตญ์ด ํํ์ ๋ถ์๊ธฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก, ์ฃผ์ด์ง ๋ฌธ์ฅ์์ ๋ช ์ฌ ๋ฑ์ ๋ฝ์ ๋ด๋ ๋ฐ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
WordCloud๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
# ์๊ฐํ์ ์ฐ์ด๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
import matplotlib.pyplot as plt
from wordcloud import WordCloud
# ํ์๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋์
๋๋ฆฌ ์์ฑ
from collections import Counter
# ๋ฌธ์ฅ์์ ๋ช
์ฌ๋ฅผ ์ถ์ถํ๋ ํํ์ ๋ถ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
from konlpy.tag import Hannanum
national_anthem ="์๋ํด๋ผ์ฐ๋ ๋ง๋๋๋ฐ ์ฌ์ฉํ ๋ฌธ์ฅ"
# Hannanum ๊ฐ์ฒด๋ฅผ ์์ฑํ ํ, .nouns()๋ฅผ ํตํด ๋ช
์ฌ๋ฅผ ์ถ์ถํฉ๋๋ค.
hannanum = Hannanum()
nouns = hannanum.nouns(national_anthem)
words = [noun for noun in nouns if len(noun) > 1]
counter = Counter(words)
wordcloud = WordCloud(
font_path = "C:/Windows/Fonts/gulim.ttc",
background_color = "white",
width = 1000,
height = 1000,
)
img = wordcloud.generate_from_frequencies(counter)
plt.imshow(img)
์ ๊ตญ๊ฐ ๊ฐ์ฌ๋ฅผ ์ฌ์ฉํ์ ๋ ๋ฐ์์ ๊ฐ์ ๊ทธ๋ฆผ์ด ์ถ๋ ฅ๋ฉ๋๋ค.

๋ค์์ ์ง์ ์น์ฌ์ดํธ๋ฅผ ์คํฌ๋ํํด์ ๊ทธ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง๊ณ ์๊ฐํ๋ฅผ ํด๋ณด์๋ค.
for i in range(1,6):
res = requests.get("https://hashcode.co.kr/?page={}".format(i), {"User-Agent":user_agent})
soup = BeautifulSoup(res.text,"html.parser")
parsed_datas = soup.find_all("li", "question-list-item")
for data in parsed_datas:
questions.append(data.h4.text.strip())
time.sleep(0.5)
words = []
hannanum = Hannanum()
for question in questions:
nouns = hannanum.nouns(question)#1๋ฒ ๋ฐ๋ณตํ ๋ ๋ช
์ฌ
words += nouns#๋์ ๋ช
์ฌ
counter = Counter(words)
wordcloud = WordCloud(
font_path = "C:/Windows/Fonts/gulim.ttc",
background_color = "white",
width = 1000,
height = 1000,
)
img = wordcloud.generate_from_frequencies(counter)
plt.imshow(img)

๐ก์๊ฐํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํด์ ๊ธ์์ ๋น๋๋ฅผ ๋ํ๋ด ์ฃผ๋ ์ด๋ฏธ์ง๋ฅผ ์ถ๋ ฅํด๋ณด์๊ณ , ๋ ๋์๊ฐ์ ์ง์ ํฌ๋กค๋งํ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํ ํด๋ณด์๋ค.