Skip to content

Commit 593189e

Browse files
author
Mingyue-Cheng
committed
Add examples and install script
1 parent f774364 commit 593189e

9 files changed

Lines changed: 226 additions & 1 deletion

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ __pycache__/
44
*.pyo
55
*.png
66
*.pdf
7+
examples/.cache/
8+
!examples/output/*.png
9+
!examples/output/*.pdf

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
PYTHON ?= python3
22

3-
.PHONY: test test-release
3+
.PHONY: test test-release example install
44

55
test:
66
PYTHON_BIN=$(PYTHON) ./scripts/self-test.sh
77

88
test-release:
99
PYTHON_BIN=$(PYTHON) ./scripts/release-test.sh
10+
11+
example:
12+
PYTHON_BIN=$(PYTHON) ./examples/generate_comparison_bar.py
13+
14+
install:
15+
./scripts/install-skill.sh

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,25 @@ The style contract is academic and conservative by default:
4545
figure-plot/
4646
├── SKILL.md
4747
├── README.md
48+
├── README_ZH.md
49+
├── LICENSE
4850
├── Makefile
4951
├── .gitignore
52+
├── agents/
53+
│ └── openai.yaml
54+
├── examples/
55+
│ ├── comparison_results.csv
56+
│ ├── generate_comparison_bar.py
57+
│ └── output/
58+
│ ├── comparison_bar_example.png
59+
│ └── comparison_bar_example.pdf
5060
├── references/
5161
│ ├── plot-presets.md
5262
│ ├── style-guide.md
5363
│ ├── data-patterns.md
5464
│ └── troubleshooting.md
5565
└── scripts/
66+
├── install-skill.sh
5667
├── check-deps.sh
5768
├── self-test.sh
5869
└── release-test.sh
@@ -65,6 +76,9 @@ figure-plot/
6576
- [references/style-guide.md](./references/style-guide.md): academic rc params, muted palette, paper sizing guidance
6677
- [references/data-patterns.md](./references/data-patterns.md): common pandas reshape / aggregation patterns
6778
- [references/troubleshooting.md](./references/troubleshooting.md): common matplotlib / seaborn issues and fixes
79+
- [examples/comparison_results.csv](./examples/comparison_results.csv): a real sample input table
80+
- [examples/generate_comparison_bar.py](./examples/generate_comparison_bar.py): a deterministic example plotting script
81+
- [scripts/install-skill.sh](./scripts/install-skill.sh): one-command install into `~/.claude/skills`
6882

6983
## Quick Start
7084

@@ -98,6 +112,43 @@ make test
98112
make test-release
99113
```
100114

115+
### 4. Generate the example figure
116+
117+
```bash
118+
make example
119+
```
120+
121+
This writes:
122+
123+
- `examples/output/comparison_bar_example.pdf`
124+
- `examples/output/comparison_bar_example.png`
125+
126+
## Install Into `~/.claude/skills`
127+
128+
To copy this skill into the default Claude skills directory:
129+
130+
```bash
131+
./scripts/install-skill.sh
132+
```
133+
134+
To install into a custom skills root:
135+
136+
```bash
137+
./scripts/install-skill.sh /path/to/skills
138+
```
139+
140+
Or:
141+
142+
```bash
143+
CLAUDE_SKILLS_HOME=/path/to/skills ./scripts/install-skill.sh
144+
```
145+
146+
## Example Output
147+
148+
The repository includes a committed example render produced from [examples/comparison_results.csv](./examples/comparison_results.csv):
149+
150+
![Example figure output](./examples/output/comparison_bar_example.png)
151+
101152
## Example User Requests
102153

103154
Typical requests that should trigger this skill:
@@ -140,6 +191,8 @@ Useful commands:
140191
git status
141192
make test
142193
make test-release
194+
make example
195+
./scripts/install-skill.sh
143196
```
144197

145198
If you modify chart defaults or export rules, rerun both test targets before pushing.

README_ZH.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@ figure-plot/
5252
├── .gitignore
5353
├── agents/
5454
│ └── openai.yaml
55+
├── examples/
56+
│ ├── comparison_results.csv
57+
│ ├── generate_comparison_bar.py
58+
│ └── output/
59+
│ ├── comparison_bar_example.png
60+
│ └── comparison_bar_example.pdf
5561
├── references/
5662
│ ├── plot-presets.md
5763
│ ├── style-guide.md
5864
│ ├── data-patterns.md
5965
│ └── troubleshooting.md
6066
├── scripts/
67+
│ ├── install-skill.sh
6168
│ ├── check-deps.sh
6269
│ ├── self-test.sh
6370
│ └── release-test.sh
@@ -73,6 +80,9 @@ figure-plot/
7380
- [references/data-patterns.md](./references/data-patterns.md):常见 pandas reshape / 聚合模式
7481
- [references/troubleshooting.md](./references/troubleshooting.md):常见 matplotlib / seaborn 问题和修复方法
7582
- [agents/openai.yaml](./agents/openai.yaml):Skill UI 元数据
83+
- [examples/comparison_results.csv](./examples/comparison_results.csv):真实示例输入数据
84+
- [examples/generate_comparison_bar.py](./examples/generate_comparison_bar.py):可运行的示例绘图脚本
85+
- [scripts/install-skill.sh](./scripts/install-skill.sh):一键安装到 `~/.claude/skills`
7686

7787
## 快速开始
7888

@@ -106,6 +116,43 @@ make test
106116
make test-release
107117
```
108118

119+
### 4. 生成示例图
120+
121+
```bash
122+
make example
123+
```
124+
125+
会生成:
126+
127+
- `examples/output/comparison_bar_example.pdf`
128+
- `examples/output/comparison_bar_example.png`
129+
130+
## 一键安装到 `~/.claude/skills`
131+
132+
默认安装到 Claude 的技能目录:
133+
134+
```bash
135+
./scripts/install-skill.sh
136+
```
137+
138+
安装到指定路径:
139+
140+
```bash
141+
./scripts/install-skill.sh /path/to/skills
142+
```
143+
144+
或者:
145+
146+
```bash
147+
CLAUDE_SKILLS_HOME=/path/to/skills ./scripts/install-skill.sh
148+
```
149+
150+
## 示例输出
151+
152+
仓库里已经提交了一份基于 [examples/comparison_results.csv](./examples/comparison_results.csv) 生成的示例图:
153+
154+
![示例图输出](./examples/output/comparison_bar_example.png)
155+
109156
## 典型触发请求
110157

111158
下面这些请求都应该触发这个 Skill:
@@ -146,6 +193,8 @@ make test-release
146193
git status
147194
make test
148195
make test-release
196+
make example
197+
./scripts/install-skill.sh
149198
```
150199

151200
如果修改了图类默认值、导出规则或脚本,至少重新跑两套测试再提交。

examples/comparison_results.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Dataset,Ours,BaselineA,BaselineB
2+
Cora,87.3,83.1,81.5
3+
Citeseer,91.2,87.5,86.0
4+
Pubmed,78.4,74.2,73.1
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python3
2+
from __future__ import annotations
3+
4+
import os
5+
from pathlib import Path
6+
7+
cache_root = Path(os.environ.get("FIGURE_PLOT_CACHE_DIR", Path(__file__).resolve().parent / ".cache"))
8+
os.environ.setdefault("MPLBACKEND", "Agg")
9+
os.environ.setdefault("MPLCONFIGDIR", str(cache_root / "mplconfig"))
10+
os.environ.setdefault("XDG_CACHE_HOME", str(cache_root / "xdg-cache"))
11+
Path(os.environ["MPLCONFIGDIR"]).mkdir(parents=True, exist_ok=True)
12+
Path(os.environ["XDG_CACHE_HOME"]).mkdir(parents=True, exist_ok=True)
13+
14+
import matplotlib.pyplot as plt
15+
import numpy as np
16+
import pandas as pd
17+
18+
19+
def main() -> int:
20+
repo_root = Path(__file__).resolve().parent.parent
21+
example_dir = repo_root / "examples"
22+
output_dir = example_dir / "output"
23+
output_dir.mkdir(parents=True, exist_ok=True)
24+
25+
csv_path = example_dir / "comparison_results.csv"
26+
df = pd.read_csv(csv_path)
27+
28+
plt.rcParams.update(
29+
{
30+
"font.family": "sans-serif",
31+
"font.sans-serif": ["Arial", "DejaVu Sans", "Helvetica"],
32+
"font.size": 9,
33+
"axes.labelsize": 9,
34+
"xtick.labelsize": 8,
35+
"ytick.labelsize": 8,
36+
"legend.fontsize": 8,
37+
"lines.linewidth": 1.8,
38+
"axes.linewidth": 0.8,
39+
"axes.facecolor": "white",
40+
"figure.facecolor": "white",
41+
"axes.grid": True,
42+
"axes.grid.axis": "y",
43+
"grid.color": "#e5e7eb",
44+
"grid.linewidth": 0.6,
45+
"axes.spines.top": False,
46+
"axes.spines.right": False,
47+
"pdf.fonttype": 42,
48+
"ps.fonttype": 42,
49+
"savefig.dpi": 300,
50+
}
51+
)
52+
53+
methods = ["Ours", "BaselineA", "BaselineB"]
54+
datasets = df["Dataset"].tolist()
55+
values = df[methods].to_numpy()
56+
colors = ["#4C6A92", "#7A8F63", "#B5875A"]
57+
58+
fig, ax = plt.subplots(figsize=(3.5, 2.5))
59+
x = np.arange(len(datasets))
60+
width = 0.22
61+
offsets = np.linspace(-(len(methods) - 1) / 2, (len(methods) - 1) / 2, len(methods)) * width
62+
63+
for i, (name, off) in enumerate(zip(methods, offsets)):
64+
ax.bar(x + off, values[:, i], width=width * 0.92, label=name, color=colors[i], zorder=3)
65+
66+
ax.set_xticks(x)
67+
ax.set_xticklabels(datasets)
68+
ax.set_ylabel("Accuracy (%)")
69+
ax.set_ylim(bottom=70)
70+
ax.legend(loc="upper right", framealpha=0.9)
71+
fig.tight_layout(pad=0.4)
72+
73+
png_path = output_dir / "comparison_bar_example.png"
74+
pdf_path = output_dir / "comparison_bar_example.pdf"
75+
fig.savefig(pdf_path, bbox_inches="tight")
76+
fig.savefig(png_path, bbox_inches="tight")
77+
78+
print(f"csv={csv_path}")
79+
print(f"png={png_path}")
80+
print(f"pdf={pdf_path}")
81+
return 0
82+
83+
84+
if __name__ == "__main__":
85+
raise SystemExit(main())
19 KB
Binary file not shown.
37.1 KB
Loading

scripts/install-skill.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
script_dir="$(cd "$(dirname "$0")" && pwd)"
5+
repo_root="$(cd "$script_dir/.." && pwd)"
6+
7+
target_root="${1:-${CLAUDE_SKILLS_HOME:-$HOME/.claude/skills}}"
8+
target_dir="$target_root/figure-plot"
9+
10+
mkdir -p "$target_root"
11+
rm -rf "$target_dir"
12+
mkdir -p "$target_dir"
13+
14+
if command -v rsync >/dev/null 2>&1; then
15+
rsync -a \
16+
--exclude '.git/' \
17+
--exclude '__pycache__/' \
18+
"$repo_root/" "$target_dir/"
19+
else
20+
cp -R "$repo_root/." "$target_dir/"
21+
rm -rf "$target_dir/.git"
22+
find "$target_dir" -name '__pycache__' -type d -prune -exec rm -rf {} +
23+
fi
24+
25+
echo "[figure-plot] installed to: $target_dir"

0 commit comments

Comments
 (0)