Chart MPL
Generate chart images from CSV files with scripts/chart_mpl.py.
Setup
Create a virtual environment and install matplotlib (one-time):
CODEBLOCK0
Quick start
Run from workspace root:
CODEBLOCK1
Output defaults to:
INLINECODE1
Inputs
- -
--csv path to CSV file - INLINECODE3 column for X axis
- INLINECODE4 numeric column(s) for Y axis — comma-separated for multi-series (e.g.
Sales,Costs) - INLINECODE6 chart type:
line, bar, hbar, pie, stacked, scatter, INLINECODE13 - Optional:
--delim if auto-detection fails (;, ,, \t, |) - Optional:
--out custom output path (PNG or SVG — format detected from extension) - Optional:
--title, --xlabel, INLINECODE22 - Optional:
--top N show only top N categories by value (bar, hbar, pie, stacked). Multi-series ranks by row total. - Optional:
--sort sort data before plotting: x-asc, x-desc, y-desc, none (default: none) - Optional:
--numfmt number format on Y axis: fr (1,5M) or en (1.5M) — default: INLINECODE33
Chart types
| Kind | Description | Multi-series |
|---|
| INLINECODE34 | Line chart with markers | yes |
| INLINECODE35 |
Vertical bar chart (grouped when multi-series) | yes |
|
hbar | Horizontal bar chart (grouped when multi-series) | yes |
|
pie | Pie chart (first Y column only) | no |
|
stacked | Stacked vertical bar (requires 2+ Y) | yes |
|
scatter | Scatter plot | yes |
|
area | Filled area chart | yes |
Notes
- - Script auto-detects delimiters when possible.
- Script tolerates European and US numeric formats (
1 234,56, 1,234.56). - Non-numeric values in
ycol are converted to NaN with a warning. - Handles BOM-encoded CSV files (
utf-8-sig). - Multi-series charts automatically show a legend and cycle through an 8-color palette.
- Y-axis ticks use human-readable formatting (K, M, G suffixes) with French or English decimals.
- INLINECODE46 keeps the N highest categories. For pie charts, the remainder is aggregated into an "Other" slice. For bar/hbar/stacked, the rest are excluded.
- Output format (PNG or SVG) is detected from the
--out file extension. Default is PNG.
End-to-end flow with SQL skill
- 1. Export query result to CSV using the
mssql skill. - Run this script on that CSV.
- Share the generated PNG path.
Chart MPL
使用 scripts/chart_mpl.py 从 CSV 文件生成图表图像。
环境设置
创建虚拟环境并安装 matplotlib(一次性操作):
bash
python3 -m venv ~/.openclaw/workspace/.venv_chart
~/.openclaw/workspace/.venv_chart/bin/pip install matplotlib
快速开始
在工作区根目录运行:
bash
~/.openclaw/workspace/.venvchart/bin/python skills/chart-mpl/scripts/chartmpl.py \
--csv /path/to/data.csv \
--xcol Mois \
--ycol Valeur \
--kind line \
--title 月度趋势 \
--xlabel 月份 \
--ylabel 数值
输出默认路径为:
~/.openclaw/workspace/exports/images
输入参数
- - --csv CSV 文件路径
- --xcol X 轴列名
- --ycol Y 轴数值列名——多系列时用逗号分隔(例如 Sales,Costs)
- --kind 图表类型:line(折线图)、bar(柱状图)、hbar(水平柱状图)、pie(饼图)、stacked(堆叠图)、scatter(散点图)、area(面积图)
- 可选:--delim 当自动检测失败时指定分隔符(;、,、\t、|)
- 可选:--out 自定义输出路径(PNG 或 SVG——根据扩展名自动识别格式)
- 可选:--title、--xlabel、--ylabel
- 可选:--top N 仅显示按数值排名前 N 的类别(柱状图、水平柱状图、饼图、堆叠图)。多系列按行总和排序。
- 可选:--sort 绘图前对数据进行排序:x-asc(X 升序)、x-desc(X 降序)、y-desc(Y 降序)、none(不排序)(默认:none)
- 可选:--numfmt Y 轴数字格式:fr(1,5M)或 en(1.5M)——默认:fr
图表类型
垂直柱状图(多系列时分组显示) | 是 |
| hbar | 水平柱状图(多系列时分组显示) | 是 |
| pie | 饼图(仅使用第一个 Y 列) | 否 |
| stacked | 堆叠垂直柱状图(需要 2 个及以上 Y 列)| 是 |
| scatter | 散点图 | 是 |
| area | 填充面积图 | 是 |
注意事项
- - 脚本会尽可能自动检测分隔符。
- 脚本兼容欧洲和美国数字格式(1 234,56、1,234.56)。
- ycol 中的非数值数据会转换为 NaN 并发出警告。
- 支持 BOM 编码的 CSV 文件(utf-8-sig)。
- 多系列图表会自动显示图例,并使用 8 色调色板循环着色。
- Y 轴刻度使用人类可读格式(K、M、G 后缀),支持法式或英式小数。
- --top N 保留排名最高的 N 个类别。对于饼图,其余部分合并为其他扇区。对于柱状图/水平柱状图/堆叠图,其余部分将被排除。
- 输出格式(PNG 或 SVG)根据 --out 文件扩展名自动识别。默认为 PNG。
与 SQL 技能的端到端流程
- 1. 使用 mssql 技能将查询结果导出为 CSV。
- 对该 CSV 运行此脚本。
- 分享生成的 PNG 路径。