visualization

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Data Visualization

数据可视化

Python libraries for creating static and interactive visualizations.
用于创建静态和交互式可视化效果的Python库。

Comparison

对比

LibraryBest ForInteractiveLearning Curve
MatplotlibPublication, full controlNoSteep
SeabornStatistical, beautiful defaultsNoEasy
PlotlyDashboards, webYesMedium
AltairDeclarative, grammar of graphicsYesEasy

最佳适用场景支持交互式学习曲线
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:
    fig, ax = plt.subplots()
    - preferred over pyplot

基础库——其他可视化库大多基于它构建。
优势:完全自定义控制、出版级质量、丰富的定制选项 局限性:代码冗长、API过时、学习曲线陡峭
核心概念
  • Figure(画布):整个绘图区域
  • Axes(坐标轴区域):单个绘图区域(一个画布可包含多个)
  • 面向对象API
    fig, ax = plt.subplots()
    ——优先于pyplot接口

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 TypeChart
Trends over timeLine chart
DistributionHistogram, box plot, violin
ComparisonBar chart, grouped bar
RelationshipScatter, bubble
CompositionPie, stacked bar
CorrelationHeatmap
Part-to-wholeTreemap, 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

决策指南

TaskRecommendation
Publication figuresMatplotlib
Quick EDASeaborn
Statistical analysisSeaborn
Interactive dashboardsPlotly
Web embeddingPlotly
Complex customizationMatplotlib
任务场景推荐库
学术出版图表Matplotlib
快速探索性数据分析(EDA)Seaborn
统计分析Seaborn
交互式仪表盘Plotly
网页嵌入Plotly
复杂自定义需求Matplotlib

Resources

资源