138 lines
3.9 KiB
Markdown
138 lines
3.9 KiB
Markdown
---
|
|
name: data-visualize-adv
|
|
label: 고급 데이터 시각화
|
|
description: Python matplotlib/seaborn을 사용하여 히트맵, 산점도, 상관관계 등 고급 시각화를 생성합니다.
|
|
icon: \uE9D9
|
|
allowed-tools:
|
|
- folder_map
|
|
- file_read
|
|
- file_write
|
|
- process
|
|
- data_pivot
|
|
- chart_create
|
|
- template_render
|
|
tabs: cowork
|
|
---
|
|
|
|
데이터를 고급 시각화 차트로 변환하세요.
|
|
## 실행 경로 선택 (Python 가능/불가)
|
|
- 먼저 `process`로 `python --version`을 확인하세요.
|
|
- Python 가능: 기존 matplotlib/seaborn 경로를 사용하세요.
|
|
- Python 불가: `data_pivot`으로 통계를 계산하고 `chart_create` + `template_render` + `file_write`로 HTML/SVG 리포트를 생성하세요.
|
|
|
|
|
|
## 사전 준비
|
|
필요한 패키지를 설치하세요:
|
|
```
|
|
process: pip install matplotlib seaborn pandas numpy
|
|
```
|
|
|
|
## 작업 절차
|
|
1. **데이터 확인**: 사용자가 제공한 CSV/JSON/Excel 데이터 파일 확인
|
|
2. **데이터 로드**: pandas로 데이터 읽기
|
|
3. **Python 스크립트 작성**: file_write로 시각화 스크립트 생성
|
|
4. **스크립트 실행**: `process`로 실행
|
|
5. **결과 확인**: 생성된 차트 이미지 경로를 사용자에게 안내
|
|
|
|
## 시각화 유형별 템플릿
|
|
|
|
### 공통 설정
|
|
```python
|
|
import matplotlib.pyplot as plt
|
|
import seaborn as sns
|
|
import pandas as pd
|
|
import numpy as np
|
|
|
|
# 한글 폰트 설정
|
|
plt.rcParams['font.family'] = 'Malgun Gothic'
|
|
plt.rcParams['axes.unicode_minus'] = False
|
|
sns.set_theme(style='whitegrid', font='Malgun Gothic')
|
|
```
|
|
|
|
### 히트맵 (상관관계 행렬)
|
|
```python
|
|
df = pd.read_csv('data.csv')
|
|
corr = df.select_dtypes(include=[np.number]).corr()
|
|
|
|
fig, ax = plt.subplots(figsize=(10, 8))
|
|
sns.heatmap(corr, annot=True, fmt='.2f', cmap='RdBu_r',
|
|
center=0, square=True, linewidths=0.5, ax=ax)
|
|
ax.set_title('상관관계 히트맵')
|
|
plt.tight_layout()
|
|
plt.savefig('heatmap.png', dpi=150)
|
|
```
|
|
|
|
### 산점도 (Scatter Plot)
|
|
```python
|
|
df = pd.read_csv('data.csv')
|
|
|
|
fig, ax = plt.subplots(figsize=(10, 8))
|
|
sns.scatterplot(data=df, x='col_x', y='col_y', hue='category',
|
|
size='value', sizes=(20, 200), alpha=0.7, ax=ax)
|
|
ax.set_title('산점도')
|
|
plt.tight_layout()
|
|
plt.savefig('scatter.png', dpi=150)
|
|
```
|
|
|
|
### 시계열 분석
|
|
```python
|
|
df = pd.read_csv('data.csv', parse_dates=['date'])
|
|
|
|
fig, ax = plt.subplots(figsize=(12, 6))
|
|
sns.lineplot(data=df, x='date', y='value', hue='category', ax=ax)
|
|
ax.set_title('시계열 트렌드')
|
|
plt.xticks(rotation=45)
|
|
plt.tight_layout()
|
|
plt.savefig('timeseries.png', dpi=150)
|
|
```
|
|
|
|
### 분포 비교 (박스플롯 + 바이올린)
|
|
```python
|
|
fig, axes = plt.subplots(1, 2, figsize=(14, 6))
|
|
|
|
sns.boxplot(data=df, x='group', y='value', ax=axes[0])
|
|
axes[0].set_title('박스플롯')
|
|
|
|
sns.violinplot(data=df, x='group', y='value', ax=axes[1])
|
|
axes[1].set_title('바이올린 플롯')
|
|
|
|
plt.tight_layout()
|
|
plt.savefig('distribution.png', dpi=150)
|
|
```
|
|
|
|
### 다중 차트 대시보드
|
|
```python
|
|
fig, axes = plt.subplots(2, 2, figsize=(14, 12))
|
|
|
|
# 좌상: 히트맵
|
|
sns.heatmap(corr, annot=True, fmt='.1f', ax=axes[0,0])
|
|
|
|
# 우상: 산점도
|
|
sns.scatterplot(data=df, x='x', y='y', ax=axes[0,1])
|
|
|
|
# 좌하: 히스토그램
|
|
sns.histplot(data=df, x='value', kde=True, ax=axes[1,0])
|
|
|
|
# 우하: 박스플롯
|
|
sns.boxplot(data=df, x='group', y='value', ax=axes[1,1])
|
|
|
|
fig.suptitle('데이터 분석 대시보드', fontsize=16, fontweight='bold')
|
|
plt.tight_layout()
|
|
plt.savefig('dashboard.png', dpi=150)
|
|
```
|
|
|
|
### 페어플롯 (변수 간 관계 전체)
|
|
```python
|
|
g = sns.pairplot(df, hue='category', diag_kind='kde')
|
|
g.fig.suptitle('변수 간 관계', y=1.02)
|
|
plt.savefig('pairplot.png', dpi=150)
|
|
```
|
|
|
|
## 스타일 옵션
|
|
- seaborn 테마: `whitegrid`, `darkgrid`, `white`, `dark`, `ticks`
|
|
- 컬러 팔레트: `Set2`, `husl`, `coolwarm`, `RdBu_r`, `viridis`
|
|
- 출력 형식: png, svg, pdf
|
|
- 해상도: `dpi=150` (기본), `dpi=300` (인쇄용)
|
|
|
|
한국어로 안내하세요. 작업 폴더에 Python 스크립트와 결과 파일을 저장하세요.
|