<jupyter_start><jupyter_text>TEXT MINING for PRACTICE: Matplotlib---<jupyter_code>import matplotlib.pyplot as plt

# 주피터 노트북에서 사용시 아래의 명령어를 추가
%matplotlib inline<jupyter_output><empty_output><jupyter_text>1. 기초<jupyter_code>import numpy as np
x = np.linspace(1, 10, 50) #n
a = np.log(x) #logn
b = x ** 2 #n^2
c = np.log(x)*x #nlogn 
d = 2**x #2
# 'r' 은 색깔 (red)
plt.plot(x, a, 'r') 
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.title('Title')
plt.show()

# plt.subplot(nrows, ncols, plot_number)
plt.subplot(1,3,1)
plt.plot(x, b, 'r*-');
plt.subplot(1,3,2)
plt.plot(x, c, 'b--');
plt.subplot(1,3,3)
plt.plot(x, d, 'g+-');

# 모양이 간격이 좀 안 맞는다 싶으면,
#plt.tight_layout()
#한 차트에 여러 그래프
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.plot(x, a, label="logN")
ax.plot(x, b, label="N^2")
ax.plot(x, c, label="NlogN")
ax.plot(x, d, label="2^N")
ax.legend()
# 차트 내부에 차트를 넣고 싶다면
fig = plt.figure()

ax1 = fig.add_axes([0,0,1,1])
ax2 = fig.add_axes([0.1,0.4,0.3,0.3])

ax1.plot(x, a, label="logN")
ax1.plot(x, b, label="N^2")
ax1.legend()

ax2.plot(x, c, label="NlogN")
ax2.plot(x, d, label="2^N")
ax2.legend()
# 특정 구간으로 그래프를 제한하고 싶다면
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])
ax.set_title("Title")
ax.plot(x, a, label="logN")
ax.plot(x, b, label="N^2")
ax.plot(x, c, label="NlogN")
ax.plot(x, d, label="2^N")
ax.set_ylim([0,100])
ax.set_xlim([3,7])
ax.legend()<jupyter_output><empty_output><jupyter_text>2. 한국어 폰트 설정나눔고딕 폰트는 [여기서](https://hangeul.naver.com/download.nhnsc_ng) 다운 받을 수 있습니다.<jupyter_code>import matplotlib.font_manager as fm
# '나눔' 이라는 단어가 들어간 폰트 확인
f = [f for f in fm.fontManager.ttflist if 'nanum' in f.name.lower()]
print(f)

plt.rcParams["font.family"] = 'NanumGothic'
plt.rcParams['font.size'] = 10.
plt.rcParams['xtick.labelsize'] = 10.
plt.rcParams['ytick.labelsize'] = 10.
plt.rcParams['axes.labelsize'] = 10.


fig, ax = plt.subplots()

# Example data
people = ['손흥민', '류현진', '김연아', '박지성', 'BTS']
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))

ax.barh(y_pos, performance, xerr=error, align='center',
        color='green', ecolor='black')
ax.set_yticks(y_pos)
ax.set_yticklabels(people)
ax.invert_yaxis()  # labels read top-to-bottom
ax.set_xlabel('투표결과')
ax.set_title('누가 한국을 빛냈는가?')

plt.show()<jupyter_output><empty_output><jupyter_text>3. 다른 차트들코드는 [여기서](https://matplotlib.org/gallery/index.html) 찾을 수 있습니다.<jupyter_code>fig, ax = plt.subplots()

for color in ['red', 'green', 'blue']:
    n = 750
    x, y = np.random.rand(2, n)
    scale = 200.0 * np.random.rand(n)
    ax.scatter(x, y, c=color, s=scale, label=color,
               alpha=0.3, edgecolors='none')

ax.legend()
ax.grid(True)

plt.show()
N_points = 100000
n_bins = 20

# Generate a normal distribution, center at x=0 and y=5
x = np.random.randn(N_points)
y = .4 * x + np.random.randn(100000) + 5

fig, axs = plt.subplots(1, 2, sharey=True)

# We can set the number of bins with the `bins` kwarg
axs[0].hist(x, bins=n_bins)
axs[1].hist(y, bins=n_bins)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20236142997704165, 'fraction_numerical': 0.034109544112823874, 'mean_word_length': 4.765595463137997, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '226868', 'license': 'Apache-2.0', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1654, 'n_words': 292, 'path': 'practice/week-02/W02_5_matplotlib.ipynb', 'repo_name': 'thejungwon/text-mining-course', 'size': '3049'}