- 라이브러리
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.graph_objects as go
1. Matplotlib
- plt.plot(x, y): 선 그래프
- plt.bar(x, y): 막대 그래프
- plt.hist(x): 히스토그램
- plt.scatter(x, y): 산점도
- plt.pie(x): 파이 차트
# labels: 항목 이름
# autopct: 항목 퍼센트
plt.pie(x, labels = labels, autopct = '%.2f')
- 여러 그래프
# 1행 2열 그래프
fig = plt.figure()
ax1 = fig.add_subplot(1, 2, 1)
ax2 = fig.add_subplot(1, 2, 2)
ax1.plot(x, y1)
ax2.plot(x, y2)
ax1.set_title('y1')
ax2.set_title('y2')
2. Seaborn
- sns.load_dataset(): 데이터셋 로드
- sns.set_style(): 배경 그리드 스타일 Ex. whitegrid, white, dark
- sns.lmplot(data, x, y): 산점도
# hue: 색깔
# col: 열 구분
# row: 행 구분
# fit_reg = False: 회귀선 출력 안함
sns.lmplot(data = data, x = x, y = y, fit_reg = False,
hue = col1, col = col2, row = col3)
- sns.histplot(data, x): 히스토그램
# bins: 막대 개수
# kde = True: 밀도 그래프
sns.histplot(data, x, bins, kde = True)
- sns.barplot(data, x, y): 막대 그래프
- sns.countplot(data, x): 빈도 막대 그래프
- sns.boxplot(data, x, y): 박스 플랏
- sns.violinplot(data, x, y): 바이올린 플랏
# split = True: 반만 출력
sns.violinplot(data, x, y, split = True)
- sns.swarmplot(data, x, y)
- sns.jointplot(data, x, y)
- sns.pairplot(data): 산점도 행렬
- sns.heatmap(data): 히트맵
# annot = True: 값 표시
# fmt = 'd': 정수 형태로 표시
# cmap: 색깔 지정
sns.heatmap(data, annot = True, fmt = 'd', cmap = 'Blues')
- sns.kdeplot(data, x, y): 커널 밀도 그래프
3. Plotly
- go.Figure(data = go.Scatter(x, y, mode = 'lines')): 선 그래프
- go.Figure(data = go.Scatter(x, y, mode = 'markers')): 산점도
- go.Figure(data = go.Scatter3d(x, y, z, mode = 'markers')): 산점도
- go.Figure(data = go.Bar(x, y)): 막대 그래프
- go.Figure(data = go.Histogram(x)): 히스토그램
- go.Figure(data = go.Box(x, y)): 박스 플랏
'Data Science' 카테고리의 다른 글
Google Colab에서 Selenium 사용하기 (0) | 2023.07.15 |
---|---|
데이터 크롤링 (0) | 2023.07.15 |
데이터 분석 기초 (0) | 2023.07.01 |
통계학 기초 (0) | 2023.06.28 |
Python 기초 (0) | 2023.06.24 |