Machine Learning/Tensorflow

11. 데이터 시각화

728x90

01. 데이터 시각화 library Matplotlib(맷플롯립)

- https://matplotlib.org
- pyplot API: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot
- 
색상값https://matplotlib.org/3.1.0/gallery/color/named_colors.html
- Color map: https://matplotlib.org/tutorials/colors/colormaps.html
- Line style: https://matplotlib.org/gallery/lines_bars_and_markers/linestyles.html
- Marker: https://matplotlib.org/api/markers_api.html
- 
그래프 지원 library

1. 실습

 /python/notebook/package/matplotlib_test.ipynb

import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import font_manager, rc

font_name = font_manager.FontProperties(fname="C:/Windows/Fonts/malgun.ttf").get_name()
# windows 10
# font_name = font_manager.FontProperties(fname="C:/Windows/Fonts/malgunsl.ttf").get_name()
rc('font', family=font_name)           # 맑은 고딕 폰트 지정
plt.rcParams["font.size"] = 12         # 글자 크기
# plt.rcParams["figure.figsize"] = (10, 4) # 10:4의 그래프 비율
plt.rcParams['axes.unicode_minus'] = False  # minus 부호는 unicode 적용시 한글이 깨짐으로 설정

# Jupyter에게 matplotlib 그래프를 출력 영역에 표시할 것을 지시하는 명령
%matplotlib inline  

.....
x = [0, 1, 2, 3, 4, 5, 6] 
y = [1, 4, 5, 8, 9, 5, 3]

.....
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
y = [9, 8, 7, 9, 8, 3, 2, 4, 3, 4]

.....
plt.plot([10, 20, 30, 40, 50], [2, 6, 8, 12, 20], label='가격')  # 선 그래프

.....
plt.plot([1, 2, 3, 4, 5], [2, 6, 8, 12, 20], label='가격')  # 선 그래프
plt.axis([0, 6, 0, 22]) # x start, x end, y start, y end

.....
xdata = np.random.normal(5, 3, 100)  # 정규 분포: 평균, 표준편차, 갯수
ydata = np.random.normal(3, 5, 100)
print(xdata)
print(type(xdata))