用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/MakiDevelop/claude-skills --skill csv-to-chart命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | csv-to-chart |
| description | 把 CSV/TSV 資料自動生成圖表(line/bar/pie/scatter)。當用戶說「畫圖表」「csv 圖表」「chart」「visualize data」時使用。 |
| argument-hint | [CSV/TSV 檔案路徑] |
| allowed-tools | Bash(python3*), Bash(pip3*), Read, Write |
| author | Maki |
| version | 1.0.0 |
| tags | ["data","visualization","chart","csv"] |
| required_env | [] |
讀取 CSV/TSV 檔案,自動偵測欄位類型,推薦並生成合適的圖表,存為 PNG。
python3 -c "import matplotlib; print(f'matplotlib {matplotlib.__version__}')" 2>/dev/null || echo "NOT_FOUND"
需要安裝 matplotlib:
pip3 install matplotlib
或者我可以幫你安裝(需確認)。
python3 << 'PYEOF'
import csv, sys, json, re
from datetime import datetime
FILE_PATH = "USER_FILE_PATH"
with open(FILE_PATH, 'r', encoding='utf-8-sig', newline='') as f:
sample_text = f.read(4096)
f.seek(0)
try:
dialect = csv.Sniffer().sniff(sample_text)
except csv.Error:
dialect = csv.excel if ',' in sample_text else csv.excel_tab
reader = csv.DictReader(f, dialect=dialect)
rows = list(reader)
if not rows:
print("ERROR: Empty file")
sys.exit(1)
columns = list(rows[0].keys())
print(f"Rows: {len(rows)}")
print(f"Columns: {columns}")
# 欄位類型偵測
date_re = re.compile(r'^\d{4}[-/]\d{1,2}[-/]\d{1,2}')
col_types = {}
for col in columns:
samples = [r[col] for r in rows[:10] if r[col]]
if not samples:
col_types[col] = "empty"
elif all(date_re.match(s) for s in samples):
col_types[col] = "date"
else:
try:
[float(s.replace(',', '')) for s in samples]
col_types[col] = "numeric"
except ValueError:
unique = len(set(r[col] for r in rows if r[col]))
col_types[col] = "category" if unique <= 20 else
(f)
dates = [c c, t col_types.items() t == ]
nums = [c c, t col_types.items() t == ]
cats = [c c, t col_types.items() t == ]
dates and nums:
(f)
cats and nums:
len((r[cats[0]] r rows)) <= 6:
(f)
:
(f)
len(nums) >= 2:
(f)
nums:
(f)
:
()
PYEOF
向用戶展示分析結果,確認:
python3 << 'PYEOF'
import csv, sys, re
from datetime import datetime
# 動態 import matplotlib
try:
import matplotlib
matplotlib.use('Agg') # 無頭模式
import matplotlib.pyplot as plt
except ImportError:
print("ERROR: matplotlib not installed. Run: pip3 install matplotlib")
sys.exit(1)
# 跨平台中文字型
plt.rcParams['font.sans-serif'] = [
'PingFang SC', # macOS
'Microsoft YaHei', # Windows
'Noto Sans CJK SC', # Linux
'SimHei', # Windows fallback
'sans-serif'
]
plt.rcParams['axes.unicode_minus'] = False
# --- 設定 ---
FILE_PATH = "USER_FILE_PATH"
CHART_TYPE = "USER_CHART_TYPE" # line / bar / pie / scatter
X_COL = "USER_X_COL"
Y_COLS = ["USER_Y_COL"] # 可多欄
TITLE = "USER_TITLE"
OUTPUT = "/tmp/chart.png"
# --- 讀取資料 ---
with open(FILE_PATH, 'r', encoding='utf-8-sig', newline='') as f:
sample_text = f.read(4096)
f.seek(0)
try:
dialect = csv.Sniffer().sniff(sample_text)
except csv.Error:
dialect = csv.excel if ',' in sample_text else csv.excel_tab
reader = csv.DictReader(f, dialect=dialect)
rows = list(reader)
# 限制行數防止卡死
if len(rows) > 5000:
import math
step = math.ceil(len(rows) / 5000)
rows = rows[::step]
print(f"Downsampled to {len(rows)} rows")
# --- 解析 ---
date_re = re.compile(r)
def parse_val(v):
not v:
None
try:
(v.replace(, ))
except ValueError:
None
def parse_date(v):
(, , ):
try:
datetime.strptime(v, )
except ValueError:
v
x_data = [parse_date(r[X_COL]) date_re.match(r.get(X_COL, )) r.get(X_COL, ) r rows]
fig, ax = plt.subplots(figsize=(12, 6))
CHART_TYPE == :
y_col Y_COLS:
y_data = [parse_val(r[y_col]) r rows]
ax.plot(x_data, y_data, marker=, markersize=2, label=y_col)
ax.legend()
CHART_TYPE == :
y_data = [parse_val(r[Y_COLS[0]]) or 0 r rows]
ax.bar(range(len(x_data)), y_data, tick_label=x_data)
plt.xticks(rotation=45, ha=)
CHART_TYPE == :
y_data = [parse_val(r[Y_COLS[0]]) or 0 r rows]
(y_data) == 0:
(, file=sys.stderr)
sys.exit(1)
len(y_data) > 10:
pairs = sorted(zip(x_data, y_data), key=lambda p: p[1], reverse=True)
top = pairs[:9]
others_sum = (v _, v pairs[9:])
x_data = [p[0] p top] + []
y_data = [p[1] p top] + [others_sum]
ax.pie(y_data, labels=x_data, autopct=)
CHART_TYPE == :
y_data = [parse_val(r[Y_COLS[0]]) r rows]
ax.scatter(x_data, y_data, alpha=0.6)
ax.set_title(TITLE, fontsize=14, fontweight=)
plt.tight_layout()
plt.savefig(OUTPUT, dpi=150, bbox_inches=)
(f)
plt.close()
PYEOF
| 類型 | 適用場景 | 自動推薦條件 |
|---|---|---|
| line | 時間序列趨勢 | X 軸為日期 + Y 軸為數值 |
| bar | 類別比較 | X 軸為分類(>6 種)+ Y 軸為數值 |
| pie | 佔比分布 | X 軸為分類(≤6 種)+ Y 軸為數值 |
| scatter | 相關性分析 | 兩個數值欄位 |
matplotlib(pip3 install matplotlib)