Skip to content

Commit 7f22091

Browse files
nainsysgitbook-bot
authored andcommitted
GitBook: [master] 2 pages and 3 assets modified
1 parent d2d7377 commit 7f22091

File tree

5 files changed

+150
-0
lines changed

5 files changed

+150
-0
lines changed

Diff for: .gitbook/assets/31401.png

29.8 KB
Loading

Diff for: .gitbook/assets/31402.png

29.7 KB
Loading

Diff for: .gitbook/assets/31403.png

50.7 KB
Loading

Diff for: 4.-numpy-and-scipy/4.2-matplotlib.md

+123
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,125 @@
11
# 4.2 Matplotlib
22

3+
Matplotlib는 파이썬에서 자료를 차트나 plot으로 데이터 시각화 패키지입니다. Matplotlib는 다음과 같은 정형화된 차트나 플롯 이외에도 다양한 시각화 기능을 제공합니다.
4+
5+
* 라인 플롯\(line plot\)
6+
* 스캐터 플롯\(scatter plot\)
7+
* 컨투어 플롯\(contour plot\)
8+
* 서피스 플롯\(surface plot\)
9+
* 바 차트\(bar chart\)
10+
* 히스토그램\(histogram\)
11+
* 박스 플롯\(box plot\)
12+
13+
Matplotlib를 사용하기 위해서는 먼저 matplotlib.pyplot 을 import 합니다. pyplot을 다른 이름으로 사용할 수 있지만 통상 plt 라는 alias를 사용합니다. 다음 plt.plot\(\)은 라인 플롯을 그리는 함수인데, 아래는 X축값 1,2,3과 Y축값 110,130,120을 가지고 라인 플롯을 그리는 예제입니다. 마지막으로 실제 그림을 표시하는 함수인 plt.show\(\)을 호출합니다.
14+
15+
```python
16+
from matplotlib import pyplot as plt
17+
18+
plt.plot(["Seoul", "Daejeon", "Busan"], [95, 137, 116])
19+
plt.xlabel('City')
20+
plt.ylabel('Response')
21+
plt.title('DeepLearning Result')
22+
plt.show()
23+
```
24+
25+
위의 코드를 실행하면 다음과 같은 결과를 출력합니다.
26+
27+
![](../.gitbook/assets/31401.png)
28+
29+
모든 x, y 쌍의 인수에 대해 선택적인 세 번째 인수가 있습니다. 이 인수는 플롯의 색상과 선 유형을 나타내는 형식 문자열입니다. 형식 문자열의 문자와 기호는 MATLAB에서 가져온 것이므로 색상 문자열을 선 스타일 문자열과 연결합니다. 기본 형식 문자열은 'b-'이며, 이는 청색 선입니다. 예를 들어 위의 내용을 빨간색 원으로 그리려면 다음과 같이 사용합니다.
30+
31+
```python
32+
from matplotlib import pyplot as plt
33+
34+
plt.plot(["Seoul", "Daejeon", "Busan"], [95, 137, 116], ‘ro’)
35+
plt.xlabel('City')
36+
plt.ylabel('Response')
37+
plt.title('DeepLearning Result')
38+
plt.show()
39+
```
40+
41+
matplotlib는 수치 처리를 위해 일반적으로 numpy 배열을 사용합니다. 아래 예제는 배열을 사용하여 하나의 명령에서 다른 형식 스타일을 가진 여러 줄을 플로팅하는 것을 보여줍니다.
42+
43+
Matplotlib는 위에서 예시한 라인 플롯 이외에 여러 다양한 차트/플롯을 그릴 수 있는데, 각 차트/플롯마다 다른 함수들을 사용합니다. 예를 들어, Bar 차트를 그리기 위해서는 plt.bar\(\) 함수를 사용하고, Pie 차트를 그리기 위해서는 plt.pie\(\)를, 히스토그램을 그리기 위해선 plt.hist\(\) 함수를 사용합니다.
44+
45+
```python
46+
from matplotlib import pyplot as plt
47+
48+
names = ['group_a', 'group_b', 'group_c']
49+
values = [1, 10, 100]
50+
51+
plt.figure(1, figsize=(9, 3))
52+
53+
plt.subplot(131)
54+
plt.bar(names, values)
55+
plt.subplot(132)
56+
plt.scatter(names, values)
57+
plt.subplot(133)
58+
plt.plot(names, values)
59+
plt.suptitle('Categorical Plotting')
60+
plt.show()
61+
```
62+
63+
![](../.gitbook/assets/31402.png)
64+
65+
다음 예제를 통해 다양한 Matplotlib의 표현을 학습해 보십시요.
66+
67+
```python
68+
import numpy as np
69+
from matplotlib import pyplot as plt
70+
from matplotlib.ticker import NullFormatter # useful for `logit` scale
71+
72+
# Fixing random state for reproducibility
73+
np.random.seed(19680801)
74+
75+
# make up some data in the interval ]0, 1[
76+
y = np.random.normal(loc=0.5, scale=0.4, size=1000)
77+
y = y[(y > 0) & (y < 1)]
78+
y.sort()
79+
x = np.arange(len(y))
80+
81+
# plot with various axes scales
82+
plt.figure(1)
83+
84+
# linear
85+
plt.subplot(221)
86+
plt.plot(x, y)
87+
plt.yscale('linear')
88+
plt.title('linear')
89+
plt.grid(True)
90+
91+
92+
# log
93+
plt.subplot(222)
94+
plt.plot(x, y)
95+
plt.yscale('log')
96+
plt.title('log')
97+
plt.grid(True)
98+
99+
100+
# symmetric log
101+
plt.subplot(223)
102+
plt.plot(x, y - y.mean())
103+
plt.yscale('symlog', linthreshy=0.01)
104+
plt.title('symlog')
105+
plt.grid(True)
106+
107+
# logit
108+
plt.subplot(224)
109+
plt.plot(x, y)
110+
plt.yscale('logit')
111+
plt.title('logit')
112+
plt.grid(True)
113+
# Format the minor tick labels of the y-axis into empty strings with
114+
# `NullFormatter`, to avoid cumbering the axis with too many labels.
115+
plt.gca().yaxis.set_minor_formatter(NullFormatter())
116+
# Adjust the subplot layout, because the logit one may take more space
117+
# than usual, due to y-tick labels like "1 - 10^{-3}"
118+
plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25,
119+
wspace=0.35)
120+
121+
plt.show()
122+
```
123+
124+
![](../.gitbook/assets/31403.png)
125+

Diff for: 4.-numpy-and-scipy/4.3-scipy.md

+27
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
11
# 4.3 SciPy
22

3+
SciPy는 파이썬을 기반으로 하여 과학, 분석, 그리고 엔지니어링을 위한 과학\(계산\)적 컴퓨팅 영역의 여러 기본적인 작업을 위한 라이브러리입니다. Scipy는 기본적으로 Numpy, Matplotlib, Pandas, Sympy등 과 함께 동작을 합니다. NumPy와 Scipy를 함께 사용하면 확장 애드온을 포함한 MATLAB을 완벽하게 대체할 수 있습니다.
4+
5+
SciPy는 NumPy위에서 구동되는 라이브러리 정도로 이해해도 무방합니다. SciPy는 기본적으로 NumPy의 ndarray를 기본 자료형으로 사용합니다. 일부 패키지는 중복되지만 SciPy가 보다 풍부한 기능을 제공합니다. SciPy는 다른 과학 컴퓨팅 영역을 다루는 하위 패키지로 구성됩니다.
6+
7+
| scipy.cluster | Vector quantization / Kmeans |
8+
| :--- | :--- |
9+
| scipy.constants | Physical and mathematical constants |
10+
| scipy.fftpack | Fourier transform |
11+
| scipy.integrate | Integration routines 수치적분 루틴과 미분방정식 해법기 |
12+
| [scipy.interpolate](https://docs.scipy.org/doc/scipy/reference/interpolate.html#module-scipy.interpolate) | Interpolation |
13+
| [scipy.io](https://docs.scipy.org/doc/scipy/reference/io.html#module-scipy.io) | Data input and output |
14+
| [scipy.linalg](https://docs.scipy.org/doc/scipy/reference/linalg.html#module-scipy.linalg) | numpy.linalg에서 제공하는 것보다 더 확장된 선형대수 루틴과 매트릭스 분해 |
15+
| [scipy.ndimage](https://docs.scipy.org/doc/scipy/reference/ndimage.html#module-scipy.ndimage) | n-dimensional image package |
16+
| [scipy.odr](https://docs.scipy.org/doc/scipy/reference/odr.html#module-scipy.odr) | Orthogonal distance regression |
17+
| [scipy.optimize](https://docs.scipy.org/doc/scipy/reference/optimize.html#module-scipy.optimize) | 함수 최적화기와 방정식의 근을 구하는 알고리즘 |
18+
| [scipy.signal](https://docs.scipy.org/doc/scipy/reference/signal.html#module-scipy.signal) | 시그널 프로세싱 도구 |
19+
| [scipy.sparse](https://docs.scipy.org/doc/scipy/reference/sparse.html#module-scipy.sparse) | 희소 행렬과 희소 선형 시스템 풀이법 |
20+
| [scipy.spatial](https://docs.scipy.org/doc/scipy/reference/spatial.html#module-scipy.spatial) | Spatial data structures and algorithms |
21+
| [scipy.special](https://docs.scipy.org/doc/scipy/reference/special.html#module-scipy.special) | 감마 함수처럼 흔히 사용되는 수학 함수를 |
22+
| [scipy.stats](https://docs.scipy.org/doc/scipy/reference/stats.html#module-scipy.stats) | 표준 연속/이산 확률 분포와 다양한 통계 테스트 |
23+
24+
SciPy에서 사용하는 기본 데이터 구조는 NumPy 모듈에서 제공하는 다차원 배열입니다. NumPy는 선형 대수학, 퓨리에 변환 및 난수 생성을 위한 몇 가지 기능을 제공하지만 SciPy에서 이와 동등한 기능을 제공하지는 않습니다.
25+
26+
기본적으로 모든 NumPy 함수는 SciPy 네임 스페이스를 통해 사용할 수 있습니다. SciPy를 가져올 때 NumPy 함수를 명시적으로 가져올 필요가 없습니다.
27+
28+
SciPy를 이해하기 위해서는 방대한 수학적 지식이 필요합니다. 여기에서 어렵고 복잡한 수학 이론은 저도잘 모르고 코드에 대한 이해를 위주로 몇 가지 예제를 돌려보겠습니다.
29+

0 commit comments

Comments
 (0)