Data Visualization
Python libraries for creating static and interactive visualizations.
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
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
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
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
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
Decision Guide
| Task |
Recommendation |
| Publication figures |
Matplotlib |
| Quick EDA |
Seaborn |
| Statistical analysis |
Seaborn |
| Interactive dashboards |
Plotly |
| Web embedding |
Plotly |
| Complex customization |
Matplotlib |
Resources
1---2name: visualization3description: Use when "data visualization", "plotting", "charts", "matplotlib", "plotly", "seaborn", "graphs", "figures", "heatmap", "scatter plot", "bar chart", "interactive plots"4---5
6# Data Visualization
7
8Python libraries for creating static and interactive visualizations.
9
10## Comparison
11
12| Library | Best For | Interactive | Learning Curve |
13|---------|----------|-------------|----------------|
14| **Matplotlib** | Publication, full control | No | Steep |
15| **Seaborn** | Statistical, beautiful defaults | No | Easy |
16| **Plotly** | Dashboards, web | Yes | Medium |
17| **Altair** | Declarative, grammar of graphics | Yes | Easy |
18
19---
20
21## Matplotlib
22
23Foundation library - everything else builds on it.
24
25**Strengths**: Complete control, publication quality, extensive customization
26**Limitations**: Verbose, dated API, learning curve
27
28**Key concepts:**
29
30- **Figure**: The entire canvas
31- **Axes**: Individual plot area (a figure can have multiple)
32- **Object-oriented API**: `fig, ax = plt.subplots()` - preferred over pyplot
33
34---
35
36## Seaborn
37
38Statistical visualization with beautiful defaults.
39
40**Strengths**: One-liners for complex plots, automatic aesthetics, works with pandas
41**Limitations**: Less control than matplotlib, limited customization
42
43**Key concepts:**
44
45- **Statistical plots**: histplot, boxplot, violinplot, regplot
46- **Categorical plots**: boxplot, stripplot, swarmplot
47- **Matrix plots**: heatmap, clustermap
48- Built on matplotlib - use matplotlib for fine-tuning
49
50---
51
52## Plotly
53
54Interactive, web-ready visualizations.
55
56**Strengths**: Interactivity (zoom, pan, hover), web embedding, Dash integration
57**Limitations**: Large bundle size, different mental model
58
59**Key concepts:**
60
61- **Express API**: High-level, similar to seaborn (`px.scatter()`)
62- **Graph Objects**: Low-level, full control (`go.Figure()`)
63- Output as HTML or embedded in web apps
64
65---
66
67## Chart Type Selection
68
69| Data Type | Chart |
70|-----------|-------|
71| Trends over time | Line chart |
72| Distribution | Histogram, box plot, violin |
73| Comparison | Bar chart, grouped bar |
74| Relationship | Scatter, bubble |
75| Composition | Pie, stacked bar |
76| Correlation | Heatmap |
77| Part-to-whole | Treemap, sunburst |
78
79---
80
81## Design Principles
82
83- **Data-ink ratio**: Maximize data, minimize decoration
84- **Color**: Use sparingly, consider colorblind users
85- **Labels**: Always label axes, include units
86- **Legend**: Only when necessary, prefer direct labeling
87- **Aspect ratio**: ~1.6:1 (golden ratio) for most plots
88
89---
90
91## Decision Guide
92
93| Task | Recommendation |
94|------|----------------|
95| Publication figures | Matplotlib |
96| Quick EDA | Seaborn |
97| Statistical analysis | Seaborn |
98| Interactive dashboards | Plotly |
99| Web embedding | Plotly |
100| Complex customization | Matplotlib |
101
102## Resources
103
104- Matplotlib: <https://matplotlib.org/stable/gallery/>
105- Seaborn: <https://seaborn.pydata.org/examples/>
106- Plotly: <https://plotly.com/python/>