visualization
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseData Visualization
数据可视化
Python libraries for creating static and interactive visualizations.
用于创建静态和交互式可视化效果的Python库。
Comparison
对比
| Library | Best For | Interactive | Learning Curve |
|---|---|---|---|
| Matplotlib | Publication, full control | No | Steep |
| Seaborn | Statistical, beautiful defaults | No | Easy |
| Plotly | Dashboards, web | Yes | Medium |
| Altair | Declarative, grammar of graphics | Yes | Easy |
| 库 | 最佳适用场景 | 支持交互式 | 学习曲线 |
|---|---|---|---|
| Matplotlib | 学术出版、完全自定义控制 | 否 | 陡峭 |
| Seaborn | 统计可视化、美观默认样式 | 否 | 简单 |
| Plotly | 仪表盘、网页应用 | 是 | 中等 |
| Altair | 声明式语法、图形语法 | 是 | 简单 |
Matplotlib
Matplotlib
Foundation library - everything else builds on it.
Strengths: Complete control, publication quality, extensive customization
Limitations: Verbose, dated API, learning curve
Key concepts:
- Figure: The entire canvas
- Axes: Individual plot area (a figure can have multiple)
- Object-oriented API: - preferred over pyplot
fig, ax = plt.subplots()
基础库——其他可视化库大多基于它构建。
优势:完全自定义控制、出版级质量、丰富的定制选项
局限性:代码冗长、API过时、学习曲线陡峭
核心概念:
- Figure(画布):整个绘图区域
- Axes(坐标轴区域):单个绘图区域(一个画布可包含多个)
- 面向对象API:——优先于pyplot接口
fig, ax = plt.subplots()
Seaborn
Seaborn
Statistical visualization with beautiful defaults.
Strengths: One-liners for complex plots, automatic aesthetics, works with pandas
Limitations: Less control than matplotlib, limited customization
Key concepts:
- Statistical plots: histplot, boxplot, violinplot, regplot
- Categorical plots: boxplot, stripplot, swarmplot
- Matrix plots: heatmap, clustermap
- Built on matplotlib - use matplotlib for fine-tuning
具备美观默认样式的统计可视化库。
优势:一行代码生成复杂图表、自动美化、兼容Pandas
局限性:自定义控制能力弱于Matplotlib、定制选项有限
核心概念:
- 统计图表:histplot、boxplot、violinplot、regplot
- 分类图表:boxplot、stripplot、swarmplot
- 矩阵图表:heatmap、clustermap
- 基于Matplotlib构建——可使用Matplotlib进行精细调整
Plotly
Plotly
Interactive, web-ready visualizations.
Strengths: Interactivity (zoom, pan, hover), web embedding, Dash integration
Limitations: Large bundle size, different mental model
Key concepts:
- Express API: High-level, similar to seaborn ()
px.scatter() - Graph Objects: Low-level, full control ()
go.Figure() - Output as HTML or embedded in web apps
支持交互式、适用于网页的可视化库。
优势:交互式操作(缩放、平移、悬停提示)、支持网页嵌入、集成Dash框架
局限性:包体积较大、思维模型与其他库不同
核心概念:
- Express API:高层接口,类似Seaborn()
px.scatter() - Graph Objects:底层接口,完全自定义控制()
go.Figure() - 可导出为HTML或嵌入网页应用
Chart Type Selection
图表类型选择
| Data Type | Chart |
|---|---|
| Trends over time | Line chart |
| Distribution | Histogram, box plot, violin |
| Comparison | Bar chart, grouped bar |
| Relationship | Scatter, bubble |
| Composition | Pie, stacked bar |
| Correlation | Heatmap |
| Part-to-whole | Treemap, sunburst |
| 数据类型 | 推荐图表 |
|---|---|
| 时间趋势 | 折线图 |
| 数据分布 | 直方图、箱线图、小提琴图 |
| 对比分析 | 条形图、分组条形图 |
| 关系分析 | 散点图、气泡图 |
| 构成分析 | 饼图、堆叠条形图 |
| 相关性分析 | 热力图 |
| 整体与部分 | 树状图、旭日图 |
Design Principles
设计原则
- Data-ink ratio: Maximize data, minimize decoration
- Color: Use sparingly, consider colorblind users
- Labels: Always label axes, include units
- Legend: Only when necessary, prefer direct labeling
- Aspect ratio: ~1.6:1 (golden ratio) for most plots
- 数据墨水比:最大化数据展示,最小化装饰元素
- 色彩使用:谨慎使用,考虑色觉障碍用户
- 标签:始终为坐标轴添加标签,包含单位
- 图例:仅在必要时使用,优先直接标注
- 宽高比:多数图表推荐约1.6:1(黄金比例)
Decision Guide
决策指南
| Task | Recommendation |
|---|---|
| Publication figures | Matplotlib |
| Quick EDA | Seaborn |
| Statistical analysis | Seaborn |
| Interactive dashboards | Plotly |
| Web embedding | Plotly |
| Complex customization | Matplotlib |
| 任务场景 | 推荐库 |
|---|---|
| 学术出版图表 | Matplotlib |
| 快速探索性数据分析(EDA) | Seaborn |
| 统计分析 | Seaborn |
| 交互式仪表盘 | Plotly |
| 网页嵌入 | Plotly |
| 复杂自定义需求 | Matplotlib |
Resources
资源
- Matplotlib: https://matplotlib.org/stable/gallery/
- Seaborn: https://seaborn.pydata.org/examples/
- Plotly: https://plotly.com/python/
- Matplotlib: https://matplotlib.org/stable/gallery/
- Seaborn: https://seaborn.pydata.org/examples/
- Plotly: https://plotly.com/python/