seaborn
它能做什么
这项技能教智能体如何用 Python 的 seaborn 库制作统计图表。它适用于快速探索数据,例如数值的分布情况,或两个变量之间的关系。
适用场景
- ✓当用户想用箱线图或小提琴图查看各组之间数值的分布情况的时候。
- ✓当用户想用配对图探索多个变量之间的关系的时候。
- ✓当用户有一张数据表,想快速生成热力图或比较图的时候。
技能链接
https://github.com/zLanqing/codex-claude-academic-skills/blob/main/scientific-toolkit-skill/references/scientific-skills/seaborn/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请展示箱线图,比较这份数据表中三个班级的测试成绩。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会把数据加载到表格中,选择匹配的 seaborn 图表类型,并使用 seaborn 的默认样式绘制。如需更细致的修改,可以使用 matplotlib。
技术内容(原始 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.
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: Full compatibility with matplotlib customization when needed
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.
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())
)
Plotting Functions by Category
Relational Plots (Relationships Between Variables)
Use for: Exploring how two or more variables relate to each other
scatterplot()- Display individual observations as pointslineplot()- Show trends and changes (automatically aggregates and computes CI)relplot()- Figure-level interface with automatic faceting
Key parameters:
x,y- Primary variableshue- Color encoding for additional categorical/continuous variablesize- Point/line size encodingstyle- Marker/line style encodingcol,row- Facet into multiple subplots (figure-level only)
# Scatter with multiple semantic mappings
sns.scatterplot(data=df, x='total_bill', y='tip',
hue='time', size='size', style='sex')
# Line plot with confidence intervals
sns.lineplot(data=timeseries, x='date', y='value', hue='category')
# Faceted relational plot
sns.relplot(data=df, x='total_bill', y='tip',
col='time', row='sex', hue='smoker', kind='scatter')
Distribution Plots (Single and Bivariate Distributions)
Use for: Understanding data spread, shape, and probability density
histplot()- Bar-based frequency distributions with flexible binningkdeplot()- Smooth density estimates using Gaussian kernelsecdfplot()- Empirical cumulative distribution (no parameters to tune)rugplot()- Individual observation tick marksdisplot()- Figure-level interface for univariate and bivariate distributionsjointplot()- Bivariate plot with marginal distributionspairplot()- Matrix of pairwise relationships across dataset
Key parameters:
x,y- Variables (y optional for univariate)hue- Separate distributions by categorystat- Normalization: "count", "frequency", "probability", "density"bins/binwidth- Histogram binning controlbw_adjust- KDE bandwidth multiplier (higher = smoother)fill- Fill area under curvemultiple- How to handle hue: "layer", "stack", "dodge", "fill"
# Histogram with density normalization
sns.histplot(data=df, x='total_bill', hue='time',
stat='density', multiple='stack')
# Bivariate KDE with contours
sns.kdeplot(data=df, x='total_bill', y='tip',
fill=True, levels=5, thresh=0.1)
# Joint plot with marginals
sns.jointplot(data=df, x='total_bill', y
常见问题
它会自己计算统计量吗?
会。这项技能说明 seaborn 内置了聚合和置信区间。
什么时候应该使用其他工具?
这项技能说明,交互式图表应使用 plotly,发表样式则应使用科学可视化技能。
它是基于 matplotlib 的吗?
是的。这项技能说明它基于 matplotlib 构建,并支持对其进行自定义。
详情
作者的原始描述
Statistical visualization with pandas integration. Use for quick exploration of distributions, relationships, and categorical comparisons with attractive defaults. Best for box plots, violin plots, pair plots, heatmaps. Built on matplotlib. For interactive plots use plotly; for publication styling use scientific-visualization.
热度
- GitHub 星标
- 5.6k
- 排名
- #14772
- 许可证
- MIT
- 更新时间
- 2026/5/14
评论
- …
同一仓库的更多技能
office-academic-skill
5.6k帮你的智能体把研究论文整理为 Word 报告,并制作可编辑、以中文为主的学术 PowerPoint 幻灯片,包含演讲者备注和版式检查。
research-writing-skill
5.6k帮你的智能体撰写、修改和润色研究论文的各部分、摘要以及审稿意见回复,并保持公式、标题和参考文献原样不变。
scientific-toolkit-skill
5.6k帮你的智能体为信号与图像处理、统计分析、仿真以及可用于发表的图表编写和调试 MATLAB 或 Python 科学代码。
matlab
5.6k帮你的智能体编写和调试 MATLAB 与 GNU Octave 脚本,用于矩阵运算、信号与图像处理、微分方程、优化以及绘图。