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