data science / data visualization
Learn Data Visualization Free: Pick the Chart, Then the Library
A 6% difference can be drawn as a 150% gap with one line of code. This page shows how, gives a chart-by-question table, compares the Python, R and JavaScript libraries by what they are for, and links the free guides and galleries that teach design rather than syntax.
Most beginners start by choosing a plotting library, learning its syntax and then wondering why their charts look wrong. The better order is to decide what the reader should compare, choose the chart form that makes that comparison easy, and only then pick a tool. Library choice is a small decision, because all of them can draw a bar chart. The mistakes that matter are in the axes, the encodings and the colors, and a library will not warn you about them.
01 · ONE LINE OF CODE
The same two numbers, drawn honestly and dishonestly
Two plans score 52 and 55. The difference is 3 points, or about 5.8%. This Matplotlib script draws the pair twice, once with the vertical axis starting at 50 and once at 0:
import matplotlib.pyplot as plt
vals = {"Plan A": 52, "Plan B": 55}
fig, (a, b) = plt.subplots(1, 2, figsize=(7, 3))
a.bar(vals.keys(), vals.values()); a.set_ylim(50, 56); a.set_title("axis starts at 50")
b.bar(vals.keys(), vals.values()); b.set_ylim(0, 60); b.set_title("axis starts at 0")
fig.savefig("axis.png")A bar encodes its value by its length, so what the reader compares is the ratio of the two bar heights on the page. Here are the drawn heights as a fraction of the plot area:
| Axis range | Plan A bar | Plan B bar | B looks this many times taller |
|---|---|---|---|
| 50 to 56 | 0.333 | 0.833 | 2.5x |
| 0 to 60 | 0.867 | 0.917 | 1.06x |
The true ratio is 55 / 52 = 1.058. The truncated axis makes the gap look 2.5 times as large as the zero-based one. The rule: bars start at zero, always, because their length is the data. Lines and dots encode by position rather than length, so a line chart of a slowly changing value can use a tighter range as long as the axis is labeled and the choice is defensible.
02 · CHART BY QUESTION
Start from what the reader should compare
| The reader should see | Use | Avoid |
|---|---|---|
| Which category is larger | Sorted horizontal bars from zero | Pies with many slices; 3D bars |
| How a value changes over time | Line chart | Bars for dozens of time points |
| How values are spread | Histogram, box plot, or density | A mean bar with no spread |
| Whether two variables move together | Scatter plot | Dual-axis lines that imply a link |
| Parts of a whole across a few groups | Stacked bar or a small table | Pie charts with near-equal slices |
If you cannot say which row your chart belongs to, the chart is probably not ready. From Data to Viz turns this table into a decision tree: pick your data type and it lists the chart forms that fit, with code and a page of common caveats.
- From Data to Viz ↗A decision tree that leads from your data type to suitable graphics, linking the code to build each and the caveats to avoid.data-to-viz.com
- Data to Viz: a collection of graphic pitfalls ↗Short illustrated entries on common mistakes, useful as a checklist before publishing a chart.data-to-viz.com
- Fundamentals of Data Visualization: visualizing amounts ↗One chapter of Claus Wilke's book, on bars, dots and heat maps. The full text is online (CC BY-NC-ND 4.0).clauswilke.com
- Fundamentals of Data Visualization: common pitfalls of color use ↗Covers encoding too much information with color, using non-monotonic color scales for data values, and not designing for color-vision deficiency.clauswilke.com
- Fundamentals of Data Visualization: telling a story and making a point ↗How to build a figure around a message instead of leaving the reader to find it.clauswilke.com
03 · LIBRARIES
Which library for which job
| Library | Language | Best for |
|---|---|---|
| Matplotlib 3.11 | Python | Full control; static figures for papers and reports; the base layer for pandas plotting and seaborn |
| seaborn 0.13 | Python | Statistical charts from DataFrames in a few lines |
| Altair 6.3 / Plotly | Python | Interactive charts; Altair is declarative and built on Vega-Lite |
| ggplot2 4.0 | R | Layered grammar of graphics; the default in R data work |
| D3 7.9 | JavaScript | Bespoke interactive graphics on the web, with a steeper learning curve |
| Observable Plot | JavaScript | Quick exploratory charts in the browser with far less code than D3 |
If you already use Python, start with Matplotlib's quick start, then seaborn. If you work in R, go straight to ggplot2, covered on the R guide. Choose D3 only when you need custom interaction on a web page; it is a toolkit, not a chart library.
- Matplotlib quick start guide ↗The official introduction to figures, axes and the two plotting interfaces. Start here before the gallery.matplotlib.org
- Choosing colormaps in Matplotlib ↗Official guidance on sequential, diverging and qualitative colormaps and why some mislead.matplotlib.org
- seaborn user guide and tutorial ↗Distributions, relationships and categorical plots, with the reasoning behind each function.seaborn.pydata.org
- Vega-Altair ↗Declarative visualization in Python: describe what data maps to what channel, and the library draws it.altair-viz.github.io
- ggplot2: Elegant Graphics for Data Analysis (3rd edition) ↗The ggplot2 book, online, for readers who want the grammar explained properly.ggplot2-book.org
- Learn D3 (Observable) ↗Mike Bostock's introduction to D3 in notebook form.observablehq.com
- Observable Plot ↗A JavaScript library for exploratory data visualization, a lighter way into web charts than D3.observablehq.github.io
- Kaggle Learn: Data Visualization ↗A short hands-on course in Python in the browser; Kaggle lists its Learn courses as no cost.kaggle.com
04 · GALLERIES
Galleries to steal from
Reproducible code beside the finished chart is the fastest way to learn what a library can do. Open a gallery, find a chart close to the one in your head, copy the code and change the data.
- Python Graph Gallery ↗Charts grouped by type, each with reproducible Python code.python-graph-gallery.com
- The R Graph Gallery ↗Hundreds of charts made with R, with the code to reproduce each.r-graph-gallery.com
- Matplotlib gallery ↗Official examples for nearly every plot type.matplotlib.org
- ColorBrewer ↗An interactive tool for choosing color schemes, with options for sequential, diverging and qualitative data.colorbrewer2.org
- Storytelling with Data blog ↗Posts on improving graphs and charts, including makeovers that explain why a revised view tells a clearer story.storytellingwithdata.com
05 · TRY IT
Redraw a chart you saw this week
06 · FAQ
Frequently asked questions
Should bar charts always start at zero?
Yes. A bar encodes its value by length, so truncating the axis exaggerates differences: in the example above, a 5.8% gap looked 2.5 times as large. Line charts encode by position and can use a tighter range if the axis is clearly labeled.
Which data visualization library should I learn first?
Use Matplotlib and seaborn if you work in Python, and ggplot2 if you work in R. Learn D3 only when you need custom interactive graphics on a web page, since it is a lower-level toolkit.
How do I choose the right chart type?
Start from the comparison you want the reader to make: category sizes call for bars, change over time for lines, spread for histograms or box plots, and relationships between variables for scatter plots. From Data to Viz offers a decision tree built on this idea.
Where can I find chart code to copy and adapt?
The Python Graph Gallery, the R Graph Gallery and the official Matplotlib gallery all show finished charts with reproducible code. Find one close to the chart you want and swap in your own data.