---
name: code-visualization-palette
description: 精美的可视化调色盘，在数据可视化中使用；若使用tidyplots包，则不必使用本技能。
title: code-visualization-palette
canonical_url: https://skilld.dev/gh/victory-hugo/s2-agent-skill/code-visualization-palette
last_updated: 2026-10-07T11:02:39.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/palette-rules.md](https://skilld.dev/api/skills-raw/victory-hugo/s2-agent-skill/code-visualization-palette/references/palette-rules.md), [references/python-visualization-examples.md](https://skilld.dev/api/skills-raw/victory-hugo/s2-agent-skill/code-visualization-palette/references/python-visualization-examples.md), [references/r-visualization-examples.md](https://skilld.dev/api/skills-raw/victory-hugo/s2-agent-skill/code-visualization-palette/references/r-visualization-examples.md).
>
> If the user asked to install this Skill, run `npx skilld install victory-hugo/s2-agent-skill/code-visualization-palette`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/code-visualization-palette`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/victory-hugo/s2-agent-skill/code-visualization-palette) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/code-visualization-palette`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/code-visualization-palette --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/code-visualization-palette --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# 代码可视化配色规范

## 概述

将本技能内置的配色规则应用到所有代码生成的图表、热图和统计图中。覆盖绘图库默认调色板，并为 Python、R 及其他绘图库显式输出 hex 颜色列表或连续色标对象。

## 强制规则

- 用户未明确指定颜色时，必须使用本技能生成的调色板。
- 若使用tidyplots包，则不必使用本技能生成的调色板。


## 图形语义到色板类型的映射

- 分类变量、分组柱状图、分组散点图、分组箱线图和离散图例，使用 `离散性配色`。
- 强度、表达量、密度、概率、单向递增热图等单方向连续变量，使用 `连续性配色-单色系`。
- log2 fold change、相关性、残差、上下调等以中点为参照的双向连续变量，使用 `连续性配色-双色系`。

## 色板优先级与数量规则

### 离散型

- 优先使用 `离散性配色-1`，其次使用 `离散性配色-2`。
- 当 `n <= 6` 时，取 `离散性配色-1` 的前 `n` 个颜色。
- 当 `7 <= n <= 11` 时，先用完整的 `离散性配色-1`，再按顺序补入 `离散性配色-2` 直到达到 `n` 个颜色。
- 当 `n > 11` 时，以 `离散性配色-1 + 离散性配色-2` 组成的 11 个锚点色进行均匀插值。
- 当 `n > 11` 时，必须提醒用户类别过多会降低颜色可辨识性，并建议合并类别、分面展示或增加形状、线型等辅助编码。

### 连续单色型

- 优先使用 `连续性单色-2`，其次为 `连续性单色-4`、`连续性单色-3`、`连续性单色-5`。
- 连续色标直接使用完整且有序的色带。
- 分箱连续图从完整色带中等距抽样出 `n` 个颜色。
- 不要打乱颜色顺序。

### 连续双色型

- 优先使用 `连续性双色-5`，其次为 `连续性双色-1`、`连续性双色-4`、`连续性双色-3`。
- 连续双色色标直接使用完整且有序的色带。
- 对称分箱时按等距方式抽取颜色，并尽量保留中点附近的平滑过渡。
- 除非用户明确要求反转高低值语义，否则不要反转左右方向。

## 语言与绘图库适配规则

- 在 Python 中，离散色板优先输出显式的 `list[str]` hex 列表，连续色标优先使用 `LinearSegmentedColormap.from_list(...)`。
- 在 R 中，离散色板优先输出显式的 `c("#xxxxxx", ...)` 向量，连续色标优先使用 `scale_*_gradientn(colours = ...)` 或等效函数。
- 在 `matplotlib`、`seaborn`、`plotly`、`ggplot2`、`ComplexHeatmap`、`altair`、`vega-lite` 等库中，必须显式传入本技能生成的调色板，不依赖默认主题色。

## 参考文件

- 具体色板、优先级、hex 顺序和数量规则见 [references/palette-rules.md](https://skilld.dev/api/skills-raw/victory-hugo/s2-agent-skill/code-visualization-palette/references/palette-rules.md)。
- Python 绘图示例见 [references/python-visualization-examples.md](https://skilld.dev/api/skills-raw/victory-hugo/s2-agent-skill/code-visualization-palette/references/python-visualization-examples.md)。
- R 绘图示例见 [references/r-visualization-examples.md](https://skilld.dev/api/skills-raw/victory-hugo/s2-agent-skill/code-visualization-palette/references/r-visualization-examples.md)。

## 输出要求

- 说明所选色板类型和具体色板名称。
- 说明需要多少个颜色，以及这些颜色是如何截取、补齐或插值得到的。
- 若离散类别过多并触发插值，应明确说明这一点。
- 除非用户要求展开解释，否则保持说明简洁。
