圖表生成
從資料表生成期刊風格的統計圖表
POST /api/v1/charts/generations 使用 multipart/form-data。所需權限:charts:generate。
服務會讀取你的資料表,自動選擇或依指定的圖表類型繪圖,最後回傳一張完成的 PNG 圖片。
不提供串流輸出或中間狀態,像其他任務一樣輪詢即可。
表單欄位
| 欄位 | 類型 | 必填 | 預設值 | 規則 |
|---|---|---|---|---|
data | file | 是 | — | CSV、TSV、TXT、XLSX 或 XLS;最大 5 MB;首列必須是唯一的欄位名稱 |
prompt | string | 否 | — | 希望呈現或強調的內容,最多 8,000 字元 |
chart_types | string | 否 | 自動 | 以逗號分隔或重複傳入,最多 4 個,值見下方清單 |
journal_style | string | 否 | default | default、nature、science、cell、plos 或 acs |
figure_width | string | 否 | double | single(單欄)或 double(雙欄) |
color_palette | string | 否 | okabe_ito | okabe_ito、wong、tol_bright 或 tol_muted |
無法解析、超過大小限制、欄位名稱重複或為空的檔案會回傳 400 INVALID_REQUEST(過大檔案的 HTTP 狀態為 413)。
圖表類型
bar, line, scatter, boxplot, violin, histogram, heatmap, regression, errorbar, timeseries, volcano, kaplan_meier, forest, dot, radar, upset, dendrogram, qq, ogive, funnel, density, roc, sankey, stem_leaf, correlation, pca, manhattan, bland_altman, waterfall, dose_response, growth_curve, standard_curve, raincloud, beeswarm, ecdf, ma_plot, enrichment, enzyme_kinetics, calendar_heatmap, choropleth, stacked_area, ridgeline, bubble, hexbin, paired_dot, precision_recall, calibration_curve, confusion_matrix.
點數
每個圖表任務消耗 10 點數,任務受理時預留,僅在成功後結算;失敗任務會釋放預留。
輸出
result.files 只包含一張期刊列印解析度的 PNG,並附上 width 與 height。
圖幅尺寸由期刊風格與欄寬決定,不同請求的像素尺寸會不同。
cURL
curl https://sci-draw.com/api/v1/charts/generations \
-H 'Authorization: Bearer sd_YOUR_KEY' \
-H 'Idempotency-Key: study-12-figure-2' \
-H 'Prefer: wait=30' \
-F 'data=@results.csv;type=text/csv' \
-F 'prompt=比較各處理組並標註顯著性' \
-F 'chart_types=boxplot' \
-F 'journal_style=nature' \
-F 'figure_width=single'JavaScript
const form = new FormData();
form.set('data', file);
form.set('prompt', '比較各處理組並標註顯著性');
form.set('chart_types', 'boxplot');
const response = await fetch('https://sci-draw.com/api/v1/charts/generations', {
method: 'POST',
headers: { Authorization: `Bearer ${apiKey}`, 'Idempotency-Key': crypto.randomUUID() },
body: form,
});Python
with open("results.csv", "rb") as table:
response = requests.post(
"https://sci-draw.com/api/v1/charts/generations",
headers={"Authorization": f"Bearer {api_key}", "Idempotency-Key": str(uuid.uuid4())},
files={"data": ("results.csv", table, "text/csv")},
data={"prompt": "比較各處理組並標註顯著性", "chart_types": "boxplot"},
)上傳的資料表屬於私有任務輸入,不會出現在任務或記錄回應中;任務到達終態後會被刪除。

API 文件