기억의 기록

Matplotlib 본문

데이터 분석/모듈&라이브러리

Matplotlib

nethunter 2018. 7. 6. 16:17
반응형

파이썬의 대표적인 시각화 도구

pip install matplotlib

https://matplotlib.org/index.html

Matplotlib 은 Figure, Axes, Axis 로 구성된다. Figure 객체는 한 개 이상의 Axes 객체를 포함하고 Axes 객체는 다시 두 개 이상의 Axis 객체를 포함한다

튜토리얼 https://matplotlib.org/users/pyplot_tutorial.html

 

 

Figure는 그림이 그려지는 캔버스나 종이를 뜻하고 Axes는 하나의 플롯, 그리고 Axis는 가로축이나 세로축 등의 축을 뜻한다.

Figure 객체 https://matplotlib.org/api/figure_api.html#Matplotlib.figure.Figure

plot 명령을 사용하면 자동으로 선언해 준다.

plt.plot(x, y, 옵션)

 

 

 

 기본적인 그래프 그려보기

 

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

 

np.random.seed(0)
f1 = plt.figure(figsize=(10, 2))  #가로 세로의 인치
#f1 = plt.lines(linewidth=(2))  #선의 두께
plt.plot(np.random.randn(100), linewidth=5, color='r')
plt.show()

 

 

 

 

plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()

 

 

 

 

 

 

def f(t):
    return np.exp(-t) * np.cos(2*np.pi*t)

t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)

plt.figure(1)
plt.subplot(211)  #numrows, numcols, fignum   두줄짜리 첫번째 컬럼 사용 번호는 1
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')

plt.subplot(212)#numrows, numcols, fignum
plt.plot(t2, np.cos(2*np.pi*t2), 'r--')
plt.show()

 

 

 

 

 

 

#plot 대신 scatter 사용
t = np.array([0,1,2,3,4,5,6,7,8,9])
y = np.array([3,7,6,1,9,7,4,4,7,2])

plt.figure(figsize=(5,3))
plt.scatter(t,y)
plt.show()

 

 

 

 

 

 colormap=t
plt.figure(figsize=(5,3))
plt.scatter(t,y, s=50, c=colormap, marker='>')
plt.colorbar()
s1 = pplt.show()

 

 

 

 

 

 

반응형

'데이터 분석 > 모듈&라이브러리' 카테고리의 다른 글

파이썬 모듈 리스트  (0) 2018.08.28
Folium  (0) 2018.07.06
Seaborn  (0) 2018.07.06