seaborn
它能做什么
Seaborn 是一个工具,可以根据你的数据绘制精美且信息丰富的图表。它能帮助你理解数字中的规律、关系和分布。
适用场景
- ✓当你的数据是表格形式,并且想将其可视化时。
- ✓当你想比较不同组别,或查看变量之间如何相互关联时。
- ✓当你制作需要清晰图表的报告或演示文稿时。
技能链接
https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/seaborn/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“用 'tips' 数据集绘制一张散点图,展示 total bill 与 tip 之间的关系,并按星期几给数据点着色。”
每周 5 个新技能,1 分钟读完。
工作原理
你提供数据(通常是表格格式),并告诉它使用哪些列作为坐标轴和颜色。Seaborn 会替你完成绘图。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Seaborn Statistical Visualization
Overview
Seaborn is a Python visualization library for creating publication-quality statistical graphics. Use this skill for dataset-oriented plotting, multivariate analysis, automatic statistical estimation, and complex multi-panel figures with minimal code.
Environment and Installation
Reviewed 2026-10-01 against the current stable Seaborn 0.13.2 documentation and released source. Native synthetic checks used Python 3.13, Seaborn 0.13.2, Matplotlib 3.11.2, pandas 3.0.6, NumPy 2.5.3, SciPy 1.18.1, and statsmodels 0.15.0. Official docs support Python 3.8+ with mandatory NumPy, pandas, and matplotlib dependencies; scipy, statsmodels, and fastcluster are optional for some advanced statistics and clustering workflows. The tested stack emits upstream pandas Copy-on-Write and Matplotlib deprecation warnings; successful current plots do not guarantee compatibility with future pandas 4 or Matplotlib 3.13.
# Reproducible install for examples in this skill
uv pip install "seaborn==0.13.2"
# Include optional statistical dependencies when needed
uv pip install "seaborn[stats]==0.13.2"
Recommended imports:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import seaborn.objects as so
sns.load_dataset() downloads public CSV example data from the moving mwaskom/seaborn-data repository when it is not cached; it returns a DataFrame and applies some dataset-specific preprocessing. No credentials are required. Cache presence does not establish dataset version: record the source revision or file hash for reproducibility. For private, regulated, or offline work, load local files explicitly with pandas and pass the resulting DataFrame to seaborn.
Design Philosophy
Seaborn follows these core principles:
- Dataset-oriented: Work directly with DataFrames and named variables rather than abstract coordinates
- Semantic mapping: Automatically translate data values into visual properties (colors, sizes, styles)
- Statistical awareness: Built-in aggregation, error estimation, and confidence intervals
- Aesthetic defaults: Publication-ready themes and color palettes out of the box
- Matplotlib integration: Matplotlib axes and artists support further customization
Quick Start
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
# Load example dataset
df = sns.load_dataset('tips')
# Create a simple visualization
sns.scatterplot(data=df, x='total_bill', y='tip', hue='day')
plt.show()
Core Plotting Interfaces
Function Interface (Traditional)
The function interface provides specialized plotting functions organized by visualization type. Each category has axes-level functions (plot to single axes) and figure-level functions (manage entire figure with faceting).
When to use:
- Quick exploratory analysis
- Single-purpose visualizations
- When you need a specific plot type
Objects Interface (Modern)
The seaborn.objects interface provides a declarative, composable API similar to ggplot2. Build visualizations by chaining methods to specify data mappings, marks, transformations, and scales. Upstream still describes this interface as experimental and incomplete in 0.13.2, although stable enough for serious use; prefer the function interface for conservative production code unless the compositional API materially simplifies the plot.
When to use:
- Complex layered visualizations
- When you need fine-grained control over transformations
- Building custom plot types
- Programmatic plot generation
from seaborn import objects as so
# Declarative syntax
(
so.Plot(data=df, x='total_bill', y='tip')
.add(so.Dot(), color='day')
.add(so.Line(), so.PolyFit(order=1))
)
Current API Notes
Seaborn 0.12 and 0.13 changed several common plotting patterns:
- Most plotting functions now require keyword arguments for variables. Prefer
sns.scatterplot(data=df, x="x", y="y")over positionalsns.scatterplot(df["x"], df["y"]). errorbarreplaces the oldciparameter inlineplot(),barplot(), andpointplot(). Regression functions such asregplot()andlmplot()still useci.- Categorical plots were rewritten in 0.13. Use
native_scale=Truewhen numeric or datetime categories should keep their original scale instead of ordinal positions.
…
常见问题
需要安装什么吗?
需要。你需要先安装 Python,然后使用 “pip install seaborn” 之类的命令安装 Seaborn 库。
Seaborn 使用什么样的数据?
它最适合“长格式数据”(long-form data)这种表格形式,即每一行是一条观测记录,每一列是一个变量。
我能使用自己的数据文件吗?
可以。你可以使用 Pandas 库从 CSV 等文件中加载数据,然后将其传给 Seaborn 来绘制图表。
详情
作者的原始描述
Creates Seaborn statistical visualizations with pandas integration for distributions, relationships, categorical comparisons, regression displays, pair plots, and heatmaps. Supports function and objects interfaces with explicit aggregation, uncertainty, and missing-data handling. Best suited to static exploratory plots; plotly covers interactive figures and scientific-visualization covers publicat
热度
- GitHub 星标
- 51k
- 排名
- #3572
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …