Best Practices for Visualizing Data

What makes a chart accurate to read, with the evidence behind each rule. Cleveland and McGill's 1984 ranking of the perceptual tasks a chart asks of its reader, from position on a common scale down to shading, and their experiments on bars and pies; the same NHANES blood pressure shares drawn as a pie, stacked bars and a dot chart; honest axes; Tufte's data-ink idea; color scales that rise steadily in lightness, measured along jet and viridis; and color pairs simulated for color-vision deficiency, where a red and green pair that differ by 120 units become nearly identical. Worked problems compute a color difference by hand from sRGB to CIELAB, show why a blue and orange that survive color-vision deficiency still merge in grayscale, and find two values that the jet map prints as the same gray.

Charts are read most accurately when they ask for positions along a common scale. Cleveland and McGill (1984) ranked the perceptual tasks from position down to shading; Heer and Bostock (2010) replicated position's lead over length, but found angle no less accurate than length. On NHANES blood pressure shares, a dot chart shows what a pie (stage 1 at 25.9%, stage 2 at 23.6%) and stacked bars hide. Ordered data need a color scale that rises steadily in CIELAB lightness, as viridis does (about 14 to 91); jet peaks at 95.9 and falls to 25.4. Matplotlib's red and green differ by $\Delta E^*_{ab} = 119.8$, but by 7.3 under simulated deuteranopia; blue and orange survive, yet can merge in grayscale.

Among NHANES adults aged 40 to 59, 36.0% have normal blood pressure under the 2017 guideline of the American College of Cardiology and American Heart Association, 14.5% have elevated pressure, 25.9% have stage 1 hypertension and 23.6% have stage 2. Drawn as a pie chart, the stage 1 and stage 2 slices look about the same size, and a reader asked which is larger, or by how much, has to guess. Drawn as four dots along one axis, the order is plain and the 2.3-point difference is visible. Nothing about the data changed; what changed is the visual task the chart asks of its reader. One chart asks for a comparison of angles and areas, the other for a comparison of positions along a scale, and people are much better at the second.

This article collects the design rules that make charts accurate to read, and gives the evidence for each where there is evidence. Its two main sources are an experimental one, Cleveland and McGill's (1984) study of graphical perception, and a measurable one, the lightness and color differences of the colors a chart uses, computed here. The rules about axes that keep a single graph honest, starting bars at zero, avoiding three-dimensional effects and dual axes, are set out with an NHANES example in Tables and Graphs for Data and are summarized here only briefly.

Graphical perception

Elementary perceptual tasks

Cleveland and McGill (1984) started from a simple observation: whatever a chart looks like, a reader who wants a number from it must perform some visual judgment, comparing the positions of two marks, the lengths of two bars, the angles of two slices, the areas of two circles. They called these judgments elementary perceptual tasks and listed ten: position along a common scale, position along nonaligned scales, length, direction, angle, area, volume, curvature, shading and color saturation. They then proposed an ordering of the tasks by how accurately people perform them, from most to least accurate:

  1. Position along a common scale
  2. Positions along nonaligned scales
  3. Length, direction, angle
  4. Area
  5. Volume, curvature
  6. Shading, color saturation

The ordering combined their own reasoning with results from psychophysics. For example, the perceived size of a length, area or volume follows a power law in its actual size, with an exponent close to 1 for length and smaller for area and still smaller for volume, so lengths are judged with little distortion while areas and volumes are systematically underestimated. Position on nonaligned scales ranks above length because a scale or frame gives extra cues (Cleveland and McGill, 1984). The authors were careful about what the ordering claims: it concerns the accuracy of extracting quantities, which is one goal of a graph among others, and items in the same rank were tied because there was not yet information to separate them.

The experiments

Two experiments tested parts of the ordering (Cleveland and McGill, 1984). In the first, people judged pairs of values on bar charts drawn in five ways, three that allowed a judgment of position along a common scale and two (divided, or stacked, bar charts) that required a judgment of length. They were asked what percentage the smaller of two marked values was of the larger, by a quick visual judgment (the replication below asked its participants to "make a quick visual judgment"). The second experiment, with a different task format, compared judgments on pie charts with judgments on ordinary bar charts. Accuracy was measured by the error on a log scale, $\log_2(|\text{judged percent} - \text{true percent}| + 1/8)$, where the $1/8$ keeps errors near zero from dominating. This much is confirmed by Heer and Bostock (2010), who copied the first experiment's charts, task and error measure.

The results agreed with the ordering. The paper's detailed figures are given here as an earlier version of this page read them; they have not been rechecked against the original, which is not openly available. As read then: 55 and 54 people took part in the two experiments, 51 in each after removing those who had not followed instructions; average errors for the length judgments were 1.4 to 2.5 times those for the position judgments; position judgments on bar charts were 1.96 times as accurate as angle judgments on pie charts, and 88% of the large errors in the second experiment came from the angle judgments; both length and angle judgments underestimated true percentages between about 25 and 50; and position judgments became less accurate as the two values were farther apart in the direction perpendicular to the common scale.

Their conclusion was that graphs should be built from tasks as high in the ordering as possible, and that several common forms, pie charts and divided bar charts among them, could be replaced by dot charts, which place each value as a point along a common scale. That core result, that position judgments are more accurate than length or angle judgments, underlies most of the advice below. It has been replicated. Heer and Bostock (2010) repeated the position and length experiment with paid online participants, using the same task and the same log error, and found the same ranking of the five judgment types, with position still significantly more accurate than length. In the same study, angle judgments on pie charts were not less accurate than length judgments, while circular areas were less accurate than both; the ordering's grouping of length, direction and angle in one rank is consistent with that.

The same blood pressure categories of NHANES adults, three ways. Left: a pie for ages 40 to 59; stage 1 (25.9%) and stage 2 (23.6%) must be compared by angle and area. Middle: stacked bars for three age groups; only the bottom segment (normal) and the top segment (stage 2) start from a common baseline, and the middle segments must be compared by length. Right: a dot chart of the same shares; every comparison, within and across age groups, is a judgment of position along one scale.
The same blood pressure categories of NHANES adults, three ways. Left: a pie for ages 40 to 59; stage 1 (25.9%) and stage 2 (23.6%) must be compared by angle and area. Middle: stacked bars for three age groups; only the bottom segment (normal) and the top segment (stage 2) start from a common baseline, and the middle segments must be compared by length. Right: a dot chart of the same shares; every comparison, within and across age groups, is a judgment of position along one scale.

Applied: pies, stacked bars and dot charts

The figure applies the ordering to the blood pressure categories of 5,232 NHANES adults with both a systolic and a diastolic reading. Within ages 40 to 59 the pie asks the reader to compare angles; the two hypertension slices differ by 2.34 points of 100, 8.4 degrees of arc. The stacked bars do better for the normal category, which starts at zero in every bar, and for stage 2, which ends at 100%, but the middle categories float: elevated pressure, 13.4% of adults aged 18 to 39, 14.5% at 40 to 59 and 18.4% at 60 and over, sits on a different base in each bar, and its growth is hard to see. The dot chart places every share on the same axis: normal pressure falls from 65.6% to 36.0% to 20.0% across the three age groups, stage 2 rises from 5.7% to 23.6% to 39.7%, and the smaller changes in the middle categories are as easy to read as the large ones.

None of this forbids pies and stacked bars. A pie with two or three slices answers "about what share of the whole?" well enough, and a stacked bar is the natural display when totals matter and the parts are secondary. The rule is to put the comparison the reader most needs to make on a common scale. In a stacked bar, that means putting the most important category at the bottom.

Honest axes

A chart is a set of encoding rules, and a chart misleads when it breaks its own rules. Tables and Graphs for Data works through the main cases on NHANES data; in brief:

  • Bars start at zero. A bar encodes a value by its length, so its length must be measured from zero. A bar chart of 58.6% and 51.1% with the axis starting at 50% shows bars in a ratio of 7.9 to 1 for values in a ratio of 1.15. Points and lines encode by position and may use an axis that does not include zero.
  • No unearned dimensions. Three-dimensional bars and pies, and icons scaled in both height and width, add depth and area that stand for nothing, and area and volume are low in the perceptual ordering anyway.
  • One scale per axis. Two vertical scales on one chart can each be stretched and shifted independently, so any two series can be made to appear to move together. Two panels with their own axes, one above the other, show the same data without the implied comparison.
  • Up and right mean more. Readers assume larger values are higher and further right. An inverted axis, larger values lower, reverses the reading of every mark, and needs a reason (depth below the surface, rank where 1 is best) and a clear label.
  • Label scale changes. A logarithmic axis turns ratios into distances; it is often the right choice (Visualizing Data with One Feature), but it must be labeled in original units at evenly spaced ratios so that readers know what equal distances mean.
  • Mind the aspect ratio. The slope of a line on a chart depends on the chart's width and height as much as on the data; stretching a chart vertically makes every trend look steeper. Cleveland, McGill and McGill (1988) studied this shape parameter and derived a way of choosing it that maximizes the accuracy of slope judgments; Cleveland (1993) presents it as "banking to 45": choosing the aspect ratio so that the average absolute orientation of the line segments is 45 degrees.

Show the data

Summary statistics can agree while the data behind them differ completely. Anscombe (1973) made the point with four sets of eleven points that share their means, variances, correlation and least-squares line, but of which only one is described well by that line; the four are drawn in Introduction to Regression, and their residual plots in Linear Regression Assumptions. The same lesson recurs throughout this topic: a correlation of 0.04 that hides a clear curve, a correlation of $-0.19$ that vanishes within groups (Visualizing Data with Multiple Features), a box plot that hides two clusters (Visualizing Data with One Feature).

Practical consequences follow. Where the number of observations allows, draw the observations, not only their summary: points over a box plot, or the individual values beside a mean and its error bar. A bar chart of group means hides how many observations each mean rests on and how widely they vary, both of which the reader needs to judge a difference. And summaries that come before a plot, in a report or a dashboard, should be checked against one.

Data-ink and clutter

Tufte (1983) proposed the data-ink ratio, the share of a graphic's ink that represents data, as a measure of its economy, with the advice to maximize it, within reason: remove gridlines, borders, backgrounds, shadows and decorations that encode nothing, and erase ink that repeats what other ink already shows. The idea is a design principle rather than an experimental result, and its qualifier matters. Some non-data ink helps: light gridlines make values easier to read off, tick labels anchor the scale, and a caption explains what to look for. What the principle rules out is ink that competes with the data for attention, such as heavy grids, hatched fills, three-dimensional effects and saturated backgrounds.

Several related habits make charts faster to read:

  • Label directly. A label placed next to a line or a group saves the reader from matching colors to a legend and back. A legend is unavoidable when marks are too dense to label, and then it should list entries in the same order as they appear in the chart.
  • Encode consistently. If women are pink circles in one chart of an analysis, they should be pink circles in every chart.
  • Sort categories by something meaningful, usually their value, unless the categories have a natural order of their own, which must be kept (Visualizing Data with One Feature shows a chart of 635 categories sorted by frequency).
  • Title and caption say what the chart shows and what to notice, with units on every axis.
  • Match the display to the reader. A violin plot or a parallel coordinates plot may be the best summary for an analyst and an obstacle for a general audience; a simple dot chart with a sentence of explanation often serves better than a sophisticated display that needs a tutorial.

Color

Color does three different jobs in charts, and each needs a different kind of scale (Harrower and Brewer, 2003; matplotlib developers, "Choosing Colormaps"):

  • Qualitative (categorical) palettes distinguish unordered categories, with colors of different hue and no implied order.
  • Sequential scales encode ordered quantities, running from light to dark (or dark to light on a dark background) in one hue or a few.
  • Diverging scales encode quantities with a meaningful midpoint, such as correlations or changes, with a neutral color at the midpoint and two hues of increasing strength on either side.

Lightness carries order

People perceive differences in lightness as differences in quantity much more reliably than differences in hue, so a color scale for ordered data should change monotonically in lightness, and in equal steps for equal steps of the data. Lightness can be measured: the CIELAB color space has a lightness coordinate $L^*$ that runs from 0 (black) to 100 (white) and was designed so that equal differences are roughly equally perceptible.

CIELAB lightness L along five of matplotlib's color maps, computed at 256 points. Jet rises from 12.9 to a peak of 95.9 at 0.64 of the way along and falls back to 25.4, so low and high values end up similarly dark and the brightest band, yellow, sits at an arbitrary value. The hsv map is cyclic and rises and falls several times. Viridis and cividis rise steadily from about 14 to 91, as a grayscale does from 0 to 100.
CIELAB lightness L* along five of matplotlib's color maps, computed at 256 points. Jet rises from 12.9 to a peak of 95.9 at 0.64 of the way along and falls back to 25.4, so low and high values end up similarly dark and the brightest band, yellow, sits at an arbitrary value. The hsv map is cyclic and rises and falls several times. Viridis and cividis rise steadily from about 14 to 91, as a grayscale does from 0 to 100.

The figure shows why the rainbow map jet, long a default in scientific software, distorts data. Its lightness rises from 12.9 at the low end to 95.9 at 64% of the way along, at the yellow band, and then falls to 25.4 at the high end. Values near the bottom and near the top are therefore similarly dark, the brightest color marks a value with no special meaning, and the rate of change in lightness varies along the map, so equal steps in the data look like unequal steps on the chart. Crameri, Shephard and Heron (2020) show that such maps visibly distort known images and patterns and are unreadable for many people with color-vision deficiency. Viridis and cividis rise in lightness from 14.9 and 13.9 to 90.9 and 91.2 without a reversal, and convert to a usable grayscale. Matplotlib's documentation recommends maps with monotonically increasing lightness for this reason, and notes that maps such as jet and hsv, which change "from darker to lighter and back to darker grey", become impossible to interpret when printed in grayscale (matplotlib developers, documentation of version 3.11.2). Worked problem 3 finds two values that jet prints as the same gray.

Color-vision deficiency

About 8% of men and 0.5% of women worldwide have a color-vision deficiency, most commonly a reduced ability to distinguish red from green; the shares are lower in some populations, such as those of sub-Saharan Africa, and likely higher in others (Crameri et al., 2020). The two most common severe forms are protanopia and deuteranopia, in which one of the three kinds of cone cell is missing. Machado, Oliveira and Fernandes (2009) model these conditions with a matrix that maps a color's red, green and blue components to the color a person with the deficiency perceives; the computation here applies their matrices to linear RGB, before the gamma encoding of sRGB, as common implementations of the model do. Applying their matrices for complete protanopia and deuteranopia to pairs of colors, and measuring the difference between the two colors of each pair as the Euclidean distance in CIELAB ($\Delta E^*_{ab}$), gives the figure below.

Four pairs of colors as seen with normal color vision, simulated for protanopia and deuteranopia (Machado et al., 2009), and reduced to lightness alone. ΔE is the CIELAB distance between the two colors of a pair (for the last row, the difference in L). Matplotlib's default red and green differ by 120 units, and by 7 under deuteranopia, when both become olive. Blue and orange stay distinct under both deficiencies, but this site's blue and orange have almost the same lightness and merge in grayscale.
Four pairs of colors as seen with normal color vision, simulated for protanopia and deuteranopia (Machado et al., 2009), and reduced to lightness alone. ΔE is the CIELAB distance between the two colors of a pair (for the last row, the difference in L*). Matplotlib's default red and green differ by 120 units, and by 7 under deuteranopia, when both become olive. Blue and orange stay distinct under both deficiencies, but this site's blue and orange have almost the same lightness and merge in grayscale.

Matplotlib's default red and green (tab:red and tab:green) differ by $\Delta E = 119.8$ with normal vision, by 37.6 under simulated protanopia and by only 7.3 under deuteranopia, when both become muddy olive. Even pure red and pure green, which also differ in lightness, fall from 170.6 to 27.8 under simulated deuteranopia (65.9 under protanopia). Blue and orange pairs survive: this site's blue and orange differ by 113.9 with normal vision, 97.3 under protanopia and 113.8 under deuteranopia, and the blue and vermilion of the palette proposed by Okabe and Ito (2008) for color-blind readers behave similarly. Hence the standard advice: avoid distinguishing categories by red against green alone, and prefer pairs built on blue against orange or yellow.

Two further results in the same computation are worth noting. First, the blue and orange that survive color-vision deficiency so well have nearly the same lightness ($L^* = 55.9$ and $54.1$, a WCAG contrast ratio of 1.07), so in grayscale print, or for the rare reader with no color vision, they are the same gray. Second, no palette of eight colors keeps every pair distinct. Under simulated protanopia, the closest pair among this site's eight series colors, its blue and its violet, differ by only $\Delta E = 2.5$, and the closest pair in matplotlib's default palette (its orange and green) by 4.6. The site's palette was checked so that adjacent slots stay distinct, which is why the slots are used in order: the smallest difference between neighboring slots is 27.6 under simulated protanopia and 40.5 under deuteranopia. The safe practice is therefore threefold, and it does not depend on color at all: use few colors, encode the same distinction redundantly by shape, line style or position, and label directly so that no reader depends on matching colors. Many tools offer palettes designed for this purpose (seaborn's "colorblind", the Okabe and Ito palette), and simulators that preview a chart as it would be seen with each deficiency.

A checklist

  1. Put the most important comparison on a common scale: positions along one axis, bars from one baseline.
  2. Start bars at zero; let points and lines use the range of the data.
  3. Prefer sorted bars or dots to pies, and dots to stacked segments for comparing parts across groups.
  4. Draw the data, not only summaries; state $n$.
  5. Label axes with units, label scale changes, and label lines and groups directly.
  6. Remove ink that encodes nothing; keep what helps reading.
  7. Use a sequential, diverging or qualitative color scale to match the data; for ordered data use one that rises steadily in lightness.
  8. Do not rely on red against green, or on color alone; check the chart in grayscale and under simulated color-vision deficiency.

Two common claims, made precise

Example (lengths against angles). A common summary says that studies consistently show lengths to be compared far more accurately than angles. The experiment most often cited for it, Cleveland and McGill (1984), compared position judgments with length judgments in one experiment and with angle judgments in another, with different task formats, so it does not compare lengths with angles directly. Its ranking separates position from length as well as from angle, and the case for dot charts rests on that first separation. The replication of Heer and Bostock (2010), which put all three kinds of judgment in the same format, found position significantly more accurate than length and did not find angle less accurate than length.

Example (default palettes and color-vision deficiency). Seaborn's default palette is sometimes described as reasonably safe for color-vision deficiency. Seaborn's documentation (version 0.13.2) describes its default as using the order of matplotlib's default palette, tab10, with slightly less intense colors. The computation above finds that tab10 includes a green and a red that differ by only 7.3 units under simulated deuteranopia, so a default should be checked, not assumed safe; seaborn's separate "colorblind" variant exists for this purpose.

Worked problems

The problems take the article's color measurements apart: one difference computed by hand, the reason a pair can survive color-vision deficiency and still fail in grayscale, and the failure of jet stated as two values with one gray. The review-pass block of the article's script checks each number.

Problem 1 (a color difference by hand). Compute $\Delta E^*_{ab}$ between matplotlib's tab:red (#d62728) and tab:green (#2ca02c) from their hexadecimal codes, and say which coordinate carries the difference.

Solution. The conversion has four steps, each undoing one layer of how a screen color is stored.

  1. Hexadecimal to sRGB. Each pair of hexadecimal digits is a value from 0 to 255; dividing by 255 gives red $(0.8392, 0.1529, 0.1569)$ and green $(0.1725, 0.6275, 0.1725)$.
  2. Remove the gamma encoding. sRGB stores values on a piecewise curve, a linear segment near zero and an offset power with exponent 2.4, close overall to a power of $1/2.2$, so each component $c$ becomes $c/12.92$ if $c \le 0.04045$ and $((c + 0.055)/1.055)^{2.4}$ otherwise. Red becomes $(0.6724, 0.0203, 0.0212)$ and green $(0.0252, 0.3515, 0.0252)$. These linear values are proportional to light intensity.
  3. Linear RGB to XYZ. A fixed matrix for the sRGB primaries and the D65 white point gives the tristimulus values. Its middle row, $Y = 0.2126R + 0.7152G + 0.0722B$, is the relative luminance: 0.1590 for red and 0.2586 for green.
  4. XYZ to CIELAB. Divide each coordinate by the white point's, apply $f(u) = u^{1/3}$ (with a linear piece near zero), and set $L^* = 116 f(Y) - 16$, $a^* = 500(f(X) - f(Y))$, $b^* = 200(f(Y) - f(Z))$. Red is $(46.8, 65.1, 44.4)$ and green $(57.9, -54.1, 48.7)$.

The differences are $\Delta L^* = -11.1$, $\Delta a^* = 119.2$ and $\Delta b^* = -4.3$, so $\Delta E^*_{ab} = \sqrt{11.1^2 + 119.2^2 + 4.3^2} = 119.8$. The $a^*$ axis, which runs from green to red, carries 99% of the squared difference. That is exactly the axis a red-green deficiency removes: the simulated deuteranope sees $(52.0, -4.8, 49.6)$ and $(56.4, -4.6, 43.8)$, two olive colors 7.3 units apart. The pair was distinct almost only in the dimension the reader lacks.

Problem 2 (why blue and orange merge in grayscale). The site's blue #3987e5 and orange #d95926 differ by $\Delta E = 113.9$ and keep 97.3 and 113.8 under the two simulations. Show where that difference lies, and compute their WCAG contrast ratio.

Solution. In CIELAB the blue is $(55.94, 8.08, -54.48)$ and the orange $(54.07, 47.76, 52.32)$. The lightness difference is 1.88, and its square is 0.03% of $\Delta E^2$; the rest lies in $a^*$ and $b^*$, mostly in $b^*$, the blue-yellow axis that red-green deficiencies leave largely intact. That is why the pair survives both simulations. Grayscale keeps lightness only, and lightness is what the pair lacks. The WCAG contrast ratio measures the same thing on relative luminance $Y$: with $Y = 0.2385$ for blue and $0.2204$ for orange, the ratio is $(0.2385 + 0.05)/(0.2204 + 0.05) = 1.07$, against the ratio of at least 3 to 1 that WCAG 2.2 requires between a graphical object needed to understand content and the colors next to it (W3C, 2024, success criterion 1.4.11). A pair robust to one loss of information is not robust to another, which is why the checklist asks for a redundant encoding by shape or position.

Problem 3 (two values, one gray). Find a value that the jet map prints with the same lightness as its top value, and compare how much lightness jet and viridis change over two intervals of the data of equal width.

Solution. Jet's lightness at the top of the scale, $t = 1$, is 25.4. On its way up from 12.9 at $t = 0$, jet first reaches 25.4 at $t = 0.069$, by interpolating between the 256 sampled points. A value 7% of the way along the scale and the maximum print as the same gray, and in color they are dark blue and dark red, which a reader with a red-green deficiency may not separate either. Over $t \in [0, 0.3]$ jet's lightness rises by 56.0, and over $[0.35, 0.65]$, an interval of the same width, by only 10.6, so equal differences in the data look five times as different in one place as in another. Viridis changes by 24.5 and 22.2 over the same two intervals, and its lightness increases at every one of the 256 points, so no two values share a gray.

Open questions

  • Do the perceptual rankings hold on this site's own charts? A replication in the manner of Heer and Bostock (2010) could use the dot chart and stacked bars of the blood pressure figure as stimuli, with the log error of Cleveland and McGill, and report how much the dot chart reduces error on the middle categories.
  • Does a newer color-difference formula change the conclusions? $\Delta E^*_{ab}$ is the simplest CIELAB distance. Recomputing the pairs and palettes with CIEDE2000 would say whether any ranking of pairs, or the closest pair of a palette, changes.
  • Which order of the site's eight colors is safest? The palette's adjacent slots stay at least 27.6 apart under simulated protanopia. A search over the $8! = 40{,}320$ orders for the one that maximizes the smallest adjacent difference under both simulations and in grayscale would say whether the current order can be improved.
  • What aspect ratio banks the blood pressure curves to 45 degrees? Cleveland's (1993) rule can be computed for the curve of mean diastolic pressure by age in Visualizing Data with Multiple Features, and the judged peak compared at the banked and the default aspect ratios.

Where it leads

The design rules of this article rest on two kinds of evidence. Experiments on graphical perception rank the visual judgments a chart can ask for, with position along a common scale first, and support replacing pies and stacked segments with dot charts when parts must be compared. Measurements of color show that a scale for ordered data should rise steadily in lightness, that red against green fails for many readers, and that a pair distinct in hue can still be identical in grayscale. The rest, honest axes, showing the data, data-ink and direct labels, follow from treating a chart as a set of encoding rules it must keep. The next article, Tools for Visualizing Data, turns to the software that applies these rules, and to the grammar of graphics, which explains why a pie chart is a bar chart in polar coordinates. A later collection on data visualization could treat perception, color science and color-vision deficiency at the depth of their own literatures.

In Python

import matplotlib.pyplot as plt
import seaborn as sns

# a dot chart: categories on one axis, shares on a common scale, one marker per group
fig, ax = plt.subplots()
for (group, row), marker in zip(shares.iterrows(), ["o", "s", "^"]):
    ax.plot(100 * row.values, range(len(row)), marker, label=f"ages {group}")
ax.set_yticks(range(len(shares.columns)), shares.columns)
ax.set_xlim(0, 70)
ax.set_xlabel("Percent of age group")

plt.imshow(values, cmap="viridis")               # sequential, rising lightness
plt.imshow(correlations, cmap="RdBu_r", vmin=-1, vmax=1)   # diverging, centered at zero
sns.set_palette("colorblind")                    # qualitative palette for color-blind readers

Every number in this article is computed by tools/experiments/data-science/data-visualization-best-practices.py in the site's repository, which takes the NHANES adults from tools/experiments/data-science/exploredata.py, implements the CIELAB conversion and the simulation matrices of Machado et al. (2009), and reads the color maps from matplotlib (version 3.10.1 for the numbers here); the figures are drawn by tools/figures/data-visualization-best-practices.py.

References

  • Anscombe, F. J. (1973). Graphs in statistical analysis. The American Statistician, 27(1), 17–21. record · 4 pages
  • Cleveland, W. S. (1993). Visualizing Data. Hobart Press. record
  • Cleveland, W. S., McGill, M. E., and McGill, R. (1988). The shape parameter of a two-variable graph. Journal of the American Statistical Association, 83(402), 289–300. record
  • Cleveland, W. S., and McGill, R. (1984). Graphical perception: Theory, experimentation, and application to the development of graphical methods. Journal of the American Statistical Association, 79(387), 531–554. record · 3 pages
  • Crameri, F., Shephard, G. E., and Heron, P. J. (2020). The misuse of colour in science communication. Nature Communications, 11, 5444. https://doi.org/10.1038/s41467-020-19160-7 record
  • Harrower, M., and Brewer, C. A. (2003). ColorBrewer.org: An online tool for selecting colour schemes for maps. The Cartographic Journal, 40(1), 27–37. record
  • Heer, J., and Bostock, M. (2010). Crowdsourcing graphical perception: Using Mechanical Turk to assess visualization design. In Proceedings of the SIGCHI Conference on Human Factors in Computing Systems (CHI '10) (pp. 203–212). https://doi.org/10.1145/1753326.1753357 record
  • Machado, G. M., Oliveira, M. M., and Fernandes, L. A. F. (2009). A physiologically-based model for simulation of color vision deficiency. IEEE Transactions on Visualization and Computer Graphics, 15(6), 1291–1298. Simulation matrices at https://www.inf.ufrgs.br/~oliveira/pubs_files/CVD_Simulation/CVD_Simulation.html record
  • matplotlib developers. Choosing colormaps in Matplotlib, documentation for version 3.11.2 (checked 23 November 2026). https://matplotlib.org/stable/users/explain/colors/colormaps.html record
  • National Center for Health Statistics (2020). National Health and Nutrition Examination Survey 2017–2018: Demographics (DEMO_J) and Blood Pressure (BPX_J) data files and documentation. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/continuousnhanes/default.aspx?BeginYear=2017 record · 109 pages
  • Okabe, M., and Ito, K. (2008). Color Universal Design (CUD): How to make figures and presentations that are friendly to colorblind people. https://jfly.uni-koeln.de/color/ record
  • Tufte, E. R. (1983). The Visual Display of Quantitative Information. Graphics Press. record · 2 pages
  • W3C (2024). Web Content Accessibility Guidelines (WCAG) 2.2, W3C Recommendation, 12 December 2024. https://www.w3.org/TR/WCAG22/ record
  • Waskom, M. L. Choosing color palettes, seaborn documentation for version 0.13.2 (checked 23 November 2026). https://seaborn.pydata.org/tutorial/color_palettes.html record
  • Whelton, P. K., Carey, R. M., Aronow, W. S., et al. (2018). 2017 ACC/AHA/AAPA/ABC/ACPM/AGS/APhA/ASH/ASPC/NMA/PCNA guideline for the prevention, detection, evaluation, and management of high blood pressure in adults. Hypertension, 71(6), e13–e115. record

Reviewed: verified, 23 Nov 2026 · citations checked, 23 Nov 2026 · editorial review, 23 Nov 2026 · 7 revisions