Lesson

Same Statistics, Different Pictures: Centre, Spread and Histograms

Why one number does not describe data: mean and median, range, standard deviation and quartiles, histograms and the log scale, on salaries in the 2026 Stack Overflow Developer Survey, with the pandas and matplotlib commands.

Last updated:


In this lesson we learn to describe data with numbers and with a picture:
measures of centre (mean and median), measures of spread (range, standard deviation and quartiles), the histogram and the log scale, and the Python commands that compute and draw them.
We work with real data: the answers of more than 30,000 developers to the 2026 Stack Overflow survey.

Four datasets with the same means

Each of the four datasets below has 200 rows, and each row holds two numbers, xx and yy⁠.
The table summarises each dataset with two numbers: the mean of xx and the mean of yy⁠.

DatasetMean of xMean of y
A52.4047.60
B52.4047.60
C52.4047.60
D52.4047.60

A measure of spread we meet in this lesson is identical in the four datasets too.

Think: judging by the table, are the four datasets alike? What would you expect to see if you drew each one?

Hint

A mean is one number that summarises 200 numbers. How many different arrangements of 200 numbers can give the same mean?

Show the datasets

In each picture every point is one row: its horizontal position is xx and its height is yy⁠.

Scatter plot of dataset A: its 200 points draw a Star of David: two overlapping triangles, as on the flag of Israel. Mean of x 52.40 and mean of y 47.60, as in the other three datasets.
Dataset A: each dot is one of its 200 rows. The four datasets are drawn on the same axes. Data: we created them ourselves with the method of Matejka and Fitzmaurice (2017), so that the statistics are the same.
Scatter plot of dataset B: its 200 points draw a dreidel: a square body with a handle on top, a point below and the letter nun on its face. Mean of x 52.40 and mean of y 47.60, as in the other three datasets.
Dataset B: each dot is one of its 200 rows. The four datasets are drawn on the same axes. Data: we created them ourselves with the method of Matejka and Fitzmaurice (2017), so that the statistics are the same.
Scatter plot of dataset C: its 200 points draw a sufganiya seen from above: a ring with a dot of jam in the middle. Mean of x 52.40 and mean of y 47.60, as in the other three datasets.
Dataset C: each dot is one of its 200 rows. The four datasets are drawn on the same axes. Data: we created them ourselves with the method of Matejka and Fitzmaurice (2017), so that the statistics are the same.
Scatter plot of dataset D: its 200 points draw a Hanukkah menorah: eight candles in a row and a taller one in the middle, on a stand. Mean of x 52.40 and mean of y 47.60, as in the other three datasets.
Dataset D: each dot is one of its 200 rows. The four datasets are drawn on the same axes. Data: we created them ourselves with the method of Matejka and Fitzmaurice (2017), so that the statistics are the same.

The four datasets are completely different: a Star of David, a dreidel, a sufganiya (a jam doughnut) and a Hanukkah menorah.
The means did not see the difference, because a mean says nothing about how the points are arranged.
We built these datasets ourselves, on purpose, so that the statistics match, in the spirit of Alberto Cairo’s Datasaurus and with the method of Matejka and Fitzmaurice (2017).
The data file holds them and five more datasets with the same statistics, and the notes file describes how we made them.

The lesson of the whole unit: before summarising data with a number, look at it.
Showing the data is critical.

How much do software developers earn?

Anyone about to start working in software wants to know how much developers earn and what is related to their pay.
To answer that we use the 2026 Stack Overflow Developer Survey:
30,903 people around the world answered questions about their work, tools, pay and use of artificial intelligence (AI) tools.

  • Who answered: people who chose to answer, mostly users of the site. This is not a representative sample of all developers in the world, so the conclusions describe the respondents.
  • Observation: each row of the file is an observation, here one respondent.
  • Variable: each column is a variable, a property recorded for every respondent (country, years of experience, salary).

The file we work with is reduced to 11 columns. The data are published under the Open Database License:
Stack Overflow Developer Survey 2026, Stack Exchange, Inc. The reduced file and the licence details are on this site.

There are two kinds of variable, and the kind decides what we can compute:

  • Quantitative variable: the values are numbers, and arithmetic on them is meaningful. Annual salary in dollars, years of experience, the number of tools a respondent uses.
  • Categorical variable: the values are categories. Country, type of employment, whether the respondent uses AI tools.

Check: the survey has an age-group column with values such as “18-24” and “25-34”.
Is it a quantitative or a categorical variable? Does a mean of this column make sense?

Answer

Age group is categorical: the values are ranges, not numbers.
They have a natural order (younger, older), but there is no single number to add and divide, so a mean of the column is not defined.
We can count how many respondents fall in each group. Had the survey asked for the age itself in years, it would be a quantitative variable.

Centre: mean and median

To answer “how much do they earn?” with one number we need a number that describes a typical value.
We start with seven respondents from Israel, the first seven in the file who gave a salary, with annual pay in thousands of dollars (rounded to the nearest thousand):

90, 163, 98, 168, 81, 65, 5090,\ 163,\ 98,\ 168,\ 81,\ 65,\ 50

The mean is the sum of the values divided by the number of values.
With nn values x1,…,xnx_1,\dots,x_n the mean is written xˉ\bar{x}⁠:

xˉ=1n∑i=1nxi=x1+x2+⋯+xnn\bar{x}=\frac{1}{n}\sum_{i=1}^{n}x_i=\frac{x_1+x_2+\cdots+x_n}{n}

For the seven respondents: xˉ=90+163+98+168+81+65+507=7157≈102.1\bar{x}=\frac{90+163+98+168+81+65+50}{7}=\frac{715}{7}\approx 102.1 thousand dollars.

The median is the value in the middle once the values are sorted from smallest to largest:
half the values are smaller than or equal to it and half are larger than or equal to it.
In the order 50,65,81,90,98,163,16850,65,81,90,98,163,168 the fourth of seven values is 90, so the median is 90 thousand dollars.
When the number of values is even there are two middle values, and the median is their mean.

Think: the largest value in the salary column of the whole survey is 31,919,350 dollars, about 32 million.
We add it as an eighth respondent to the seven. What happens to the mean, and what happens to the median?

A: both grow by about the same amount

The thinking: a large value was added, so any measure of a “typical value” grows.

The mistake: the median depends only on the values in the middle of the order.
With eight values the median is the mean of the fourth and fifth, 90+982=94\frac{90+98}{2}=94⁠:
a change of 4 thousand. The mean, on the other hand, jumps to about 4.1 million.

B: the median jumps and the mean hardly changes

The thinking: the new value is the largest, so the “middle” moves towards it.

The mistake: the median is the value in the middle position of the order, not the value in the middle of the range.
One value at the end moves the middle position by half a step only:
from 90 to 94. The mean is the one that adds the enormous value, so it is the one that jumps.

C: the mean jumps and the median hardly changes

The thinking: the mean adds up every value, so one enormous value pulls it:
715+31,9198=32,6348≈4,079\frac{715+31{,}919}{8}=\frac{32{,}634}{8}\approx 4{,}079 thousand dollars, more than four million. The median depends only on the order:
the new value joins at the end, and the median moves from 90 to 90+982=94\frac{90+98}{2}=94⁠.

We call a value far away from the rest an outlier. The median is resistant to outliers and the mean is not:
one outlier pulls the mean, while the median depends only on the order.

A salary of 31.9 million dollars is almost certainly a typing or conversion error.
Before computing statistics on the salary column we must decide what to do about two kinds of problem:

  • Missing values: 17,396 respondents (56%) gave no salary. Their cell is empty in the file, and pandas shows it as NaN (Not a Number). They are not missing at random: 2,747 of the 3,139 students gave no salary, and 1,359 of the 1,742 people not employed. 9,422 employed respondents gave no salary either, so any statistic on salary describes only those who chose to answer.
  • Implausible values: zeros, a few dollars a year, and tens of millions.

In this lesson we keep annual salaries between 1,000 and 1,000,000 dollars, which leaves 12,969 respondents.
A rule like this is a decision, so we state it next to every result.

For these 12,969 respondents: the mean is 99,020 dollars and the median 81,884 dollars. Most respondents earn less than the “average salary”, because a few very high salaries pull the mean up.
When someone says “the average developer salary”, it is worth asking whether they mean the mean or the median.
Salaries in the survey are annual pay converted to US dollars at market exchange rates, with no adjustment for the cost of living.

Spread: range, standard deviation and quartiles

Two groups with the same median can live in different worlds:
in one, everyone earns about the same; in the other, the gaps are huge.
A measure of centre does not see this. A measure of spread describes how far apart the values are.

The range is the difference between the largest and the smallest value.
For the seven respondents: 168−50=118168-50=118 thousand dollars. The range depends on two values only, so a single outlier changes it completely.

The standard deviation measures how far the values typically are from the mean.
We build it in steps for the seven respondents, with xˉ≈102.14\bar{x}\approx 102.14⁠:

Salary xix_iDeviation xi−xˉx_i-\bar{x}Squared deviation
90−12.14147.4
16360.863,703.6
98−4.1417.2
16865.864,337.2
81−21.14447.0
65−37.141,379.6
50−52.142,718.9
  1. Compute the deviation of each value from the mean. The deviations always add up to zero (positive and negative cancel), so their sum cannot be used directly.
  2. Square each deviation, so that all of them are positive. The sum: 12,750.912{,}750.9⁠.
  3. Divide by n−1=6n-1=6 to get the sample variance: s2=12,750.96≈2,125.1s^2=\frac{12{,}750.9}{6}\approx 2{,}125.1⁠.
  4. Take the square root to get the sample standard deviation, returning to the units of the data (thousands of dollars, not their square): s=2,125.1≈46.1s=\sqrt{2{,}125.1}\approx 46.1⁠.
s=1n−1∑i=1n(xi−xˉ)2s=\sqrt{\frac{1}{n-1}\sum_{i=1}^{n}\left(x_i-\bar{x}\right)^2}

The seven respondents are a sample: part of a larger group, all the respondents from Israel who gave a salary.
We do not know the variance of the whole group, and s2s^2 estimates it from the sample.
A number computed from a sample to estimate an unknown value of the whole group is called an estimator, so s2s^2 is an estimator of the variance, and ss of the standard deviation.
When all the values of the group are known, its variance is the mean of the squared deviations, that is, division by nn⁠; this is also how variance is defined in probability.
When we estimate from a sample we divide by n−1n-1⁠, and this is also the default in pandas.

Why divide by n−1n-1 and not by nn?

We measure the deviations from xˉ\bar{x}⁠, the mean of the sample, not from the mean of the whole group, which we do not know.
Of all numbers, xˉ\bar{x} is the one with the smallest sum of squared deviations.
For every number cc⁠:

∑i=1n(xi−c)2=∑i=1n(xi−xˉ)2+n(xˉ−c)2\sum_{i=1}^{n}(x_i-c)^2=\sum_{i=1}^{n}(x_i-\bar{x})^2+n(\bar{x}-c)^2

To see this, write xi−c=(xi−xˉ)+(xˉ−c)x_i-c=(x_i-\bar{x})+(\bar{x}-c) and expand the square. The cross term vanishes, because the deviations from xˉ\bar{x} add up to zero.
The last term is never negative, so the smallest sum is at c=xˉc=\bar{x}⁠.
For the seven respondents, the sum around xˉ≈102.1\bar{x}\approx 102.1 is 12,750.9, and around 100 it is 12,783:
larger by 7⋅(102.14−100)2≈32.17\cdot(102.14-100)^2\approx 32.1⁠.

The mean of the whole group usually differs from xˉ\bar{x}⁠, so the sum of squared deviations from it is larger.
Measured from xˉ\bar{x} the sum comes out too small in a systematic way, and dividing by n−1n-1 instead of nn makes the result a little larger to make up for it.
The proof that this correction is exact, on average over many samples, is in the unit on estimation (week 8).

Quartiles. The median splits the sorted values into two halves.
The first quartile Q1Q_1 is the median of the lower half, and the third quartile Q3Q_3 is the median of the upper half.
So a quarter of the values are below Q1Q_1 and a quarter are above Q3Q_3⁠.
When the number of values is odd, the median itself belongs to neither half.

For the seven respondents, in the order 50,65,81,90,98,163,16850,65,81,\mathbf{90},98,163,168⁠: the lower half is 50,65,8150,65,81⁠, so Q1=65Q_1=65⁠; the upper half is 98,163,16898,163,168⁠, so Q3=163Q_3=163⁠.

The interquartile range (IQR) is Q3−Q1Q_3-Q_1⁠: 163−65=98163-65=98⁠. It is the width of the middle half of the values, and outliers at the ends do not affect it.

For the whole survey (12,969 respondents): Q1=45,805Q_1=45{,}805 and Q3=130,000Q_3=130{,}000⁠, so half of the respondents earn between about 46 thousand and 130 thousand dollars a year.

Check: we add the salary of 31.9 million to the seven respondents.
What happens to the range, the standard deviation and the IQR?

Answer

The range and the standard deviation jump, because both depend on the extreme value:
the range becomes about 31,869 thousand, and the standard deviation rises to thousands of thousands.
The IQR hardly changes: with eight values the lower half is 50,65,81,9050,65,81,90 and Q1=65+812=73Q_1=\frac{65+81}{2}=73⁠, the upper half is 98,163,168,31,91998,163,168,31{,}919 and Q3=163+1682=165.5Q_3=\frac{163+168}{2}=165.5⁠, so IQR=92.5\mathrm{IQR}=92.5⁠.
Like the median, the quartiles are resistant to outliers.

Statistics in pandas

The pandas library loads a table file into an object called a DataFrame:
a table with named columns. We use these commands:

  • pd.read_csv(name) reads a CSV file and returns a DataFrame.
  • df[‘salary_usd’] returns one column.
  • A condition on a column, such as df[‘salary_usd’] >= 1000, returns True or False for each row, and df[condition] keeps only the rows where the condition holds. Two conditions are joined with &, each in parentheses.
  • describe() returns the number of values (count, without the missing ones), the mean, the standard deviation, the minimum, the quartiles and the maximum. median() returns the median, and quantile(q) returns the value below which a share qq of the values lie.
import pandas as pd

df = pd.read_csv('so-2026-week1.csv')
salary = df['salary_usd']
ok = salary[(salary >= 1000) & (salary < 1000000)]
print(len(df), salary.count(), len(ok))
print(ok.describe().round(0))
print(ok.median(), ok.quantile(0.25), ok.quantile(0.75))
30903 13507 12969
count     12969.0
mean      99020.0
std       85080.0
min        1000.0
25%       45805.0
50%       81884.0
75%      130000.0
max      930981.0
Name: salary_usd, dtype: float64
81884.0 45805.0 130000.0

The row 25% of describe is Q1Q_1 and the row 75% is Q3Q_3⁠. pandas computes quartiles by interpolating between neighbouring values, so on small data the result can differ a little from the hand method.
For the seven respondents, for example, quantile(0.25) returns 73, not 65, and quantile(0.75) returns 130.5, not 163.
By hand we use the method of halves, and in code the pandas method; it matters to know which method is used where.
On large data the difference is negligible.

What does this program compute?

young = df[df['age_group'] == '18-24 years old']['salary_usd']
young = young[(young >= 1000) & (young < 1000000)]
print(young.median())
Answer

The program keeps only respondents in the 18 to 24 age group, then only salaries between 1,000 and 1,000,000 dollars, and prints the median of what is left:
the middle salary of the young respondents. You can run it in the box above (at the end of the box) and compare it with the median of all respondents.

Histograms

Statistics summarise the data in a few numbers. To see the whole distribution, that is, which values occur and how often, we draw a histogram:

  1. Split the range of the values into intervals of equal width, called bins.
  2. Count how many values fall in each interval.
  3. Draw a bar for each interval whose height is the number of values in it.
Histogram of 12,969 annual salaries in bins of 10,000 dollars. The tallest bar is 60,000 to 70,000 dollars (977 people); the bars fall slowly to the right in a long tail, so the mean (99,020) is above the median (81,884).
Each bar counts respondents in a 10,000-dollar range (12,969 salaries between 1,000 dollars and a million). The 180 salaries of 400,000 dollars or more lie beyond the right edge. Data: Stack Overflow Developer Survey 2026, Stack Exchange, Inc., licensed under ODbL 1.0.

Words that describe the shape of a histogram:

  • Peak: the region of the highest bars. Here between 50 and 80 thousand dollars. The first bar, salaries below 10,000 dollars a year, is almost as high as the peak.
  • Symmetry: folding the picture around its middle, the two sides almost match.
  • Tail: one side where the bars stretch far and low. Salary has a long right tail: a few respondents earn much more than everyone else.

The right tail is why the mean (99,020) is above the median (81,884):
the values in the tail pull the mean towards them, and the median does not move.

Check: the histogram uses bins 10,000 dollars wide. What changes if we draw it with bins 100,000 dollars wide?

Answer

There will be only four bars up to 400 thousand dollars. Almost all respondents fall in the first or second bar, and the shape disappears:
we no longer see that the peak lies between 50 and 80 thousand, nor that there is a high bar near zero.
Bins that are too narrow cause the opposite problem: each bin holds few values and the picture looks like noise.
The bin width is a choice, and it is worth trying several widths before drawing a conclusion about the shape.

The log scale

In the histogram of salary the right tail squeezes all the respondents into the left third of the picture, and we can hardly see what happens between 5,000 and 50,000 dollars.
On a log scale every equal step along the axis is a multiplication by the same number:
the distance from 1,000 to 10,000 equals the distance from 10,000 to 100,000.
Mathematically we plot log⁡10x\log_{10}x instead of xx and label the axis with the original values.

The same 12,969 salaries on a scale where each step is ten times more (1,000, 10,000, 100,000, 1,000,000 dollars), with bars of equal width on that scale. The long right tail of the ordinary histogram becomes a hump with its top at 100,000 to 116,591 dollars, and a thinner tail now shows on the left, at low salaries.
The same 12,969 salaries on a logarithmic axis: each bar covers the same ratio between its highest and lowest salary. Data: Stack Overflow Developer Survey 2026, Stack Exchange, Inc., licensed under ODbL 1.0.

On this scale the whole range is visible: hundreds of respondents earning a few thousand dollars a year, the peak around 100 thousand, and the decline towards a million.
The tail that squeezed the ordinary picture spreads out, and the high bar near zero in the ordinary picture spreads over several bars.

A log axis changes only the picture. The mean and the median of the salaries themselves stay the same numbers in dollars.
Something does change when we compute the statistics on the logarithms of the values and turn the result back into the original units.
We check with three values, 10, 100 and 1,000:

  • The median is 100. The log⁡10\log_{10} of the values are 1,2,31,2,3⁠, with median 2, which is again 102=10010^2=100⁠. Taking log⁡\log keeps the order, so with an odd number of values the middle value stays the same value. With an even number the median is the mean of two values, and there the result can change: for 10 and 1,000 the median is 505, while the median of the logarithms, 2, gives back 100. In large data, where the two middle values are close, the difference is negligible.
  • The mean is 10+100+10003=370\frac{10+100+1000}{3}=370⁠, but the mean of the logarithms is 1+2+33=2\frac{1+2+3}{3}=2⁠, that is 102=10010^2=100⁠. On a log scale the “middle” given by the mean moves.

Check: two respondents earn 20,000 and 40,000 dollars, and two others earn 100,000 and 120,000 dollars.
On a log scale, which pair is further apart?

Answer

The first pair. On a log scale the distance depends on the ratio of the values, not on their difference:
40,00020,000=2\frac{40{,}000}{20{,}000}=2 and 120,000100,000=1.2\frac{120{,}000}{100{,}000}=1.2⁠. The difference is the same (20 thousand), but in the first pair one salary is double the other, and on a log scale that is a larger distance.

Histograms in matplotlib

The matplotlib library draws charts. We use these commands:

  • plt.hist(values, bins=b) draws a histogram. When b is a number, the range is split into b equal bins; when b is a list of edges, those are the edges of the bins.
  • np.logspace(3, 6, 31) from the numpy library returns 31 edges from 10310^3 to 10610^6⁠, equally spaced on a log scale.
  • plt.xscale(‘log’) turns the horizontal axis into a log scale.
import numpy as np
import matplotlib.pyplot as plt

plt.hist(ok, bins=np.arange(0, 410000, 10000))
plt.xlabel('salary (USD)')
plt.show()
Histogram of salaries from 0 to 400,000 dollars in bins 10,000 dollars wide: the first bar, below 10,000, is almost as tall as the peak between 50 and 80 thousand, and a long right tail stretches towards 400,000.
plt.hist(ok, bins=np.logspace(3, 6, 31))
plt.xscale('log')
plt.xlabel('salary (USD, log scale)')
plt.show()
Histogram of salaries on a log scale from 1,000 to 1,000,000 dollars: low, almost flat bars at a few thousand dollars, a single peak around 100 thousand and a fast decline towards a million.

What does this program compute?

counts, edges, bars = plt.hist(ok, bins=np.arange(0, 410000, 10000))
print(edges[counts.argmax()])
Answer

plt.hist also returns the number of values in each bin (counts) and the edges of the bins (edges).
counts.argmax() is the index of the highest bar, and the program prints its left edge:
the start of the 10,000-dollar interval that holds the most respondents, that is, the peak of the histogram.

What the statistics missed

Back to the four datasets from the start of the lesson. Their means are identical, and so are their standard deviations:
s=19.6s=19.6 for xx and s=17.8s=17.8 for yy in every dataset. The medians and quartiles already differ a little, because they depend on the order of the values, not only on sums.
What told them apart was the shape: where the points cluster, where the gaps are, and what pattern they form.
We saw the same with salary: the mean and the median each gave one number, and the histogram on a log scale showed a thousandfold range between respondents.

A scatter plot draws each row as a point: xx sets how far right and yy how far up.
That is how we drew the four datasets at the start of the lesson.
Try the tool: choose a set, and compare the statistics in the table with the scatter plot and with the histograms of xx and of yy⁠.
What changes from set to set, and what hardly changes?

In the interactive version of the tool we choose a set and see it as a scatter plot and a histogram. The table summarises each set by the mean and the standard deviation of x and of y: the numbers are the same in every set, and the difference between the sets shows only in the picture.

The sets of the tool and their statistics
SetMean xMean ySD xSD y
Cloud52.4047.6019.6017.80
Star of David52.4047.6019.6017.80
Shofar52.4047.6019.6017.80
Dreidel52.4047.6019.6017.80
Sufganiya52.4047.6019.6017.80
Purim mask52.4047.6019.6017.80
Megillah52.4047.6019.6017.80
Hanukkah menorah52.4047.6019.6017.80
Map of Israel52.4047.6019.6017.80

Think: which statistic and which chart would you choose in each situation?

  1. A company advertises “our average salary is above the market”, and you are considering applying.
  2. A team wants to know whether a server’s response times are stable or vary a lot from request to request.
  3. You check whether a sensor’s data contain values that look like measurement errors.
Answer
  1. The median, and better still a histogram: a high mean can come from a few senior salaries while most employees earn less. The question to ask is the median and the interquartile range for your role.
  2. A measure of spread: the standard deviation, or the IQR if there are a few outliers we do not care about. A histogram shows whether most requests are fast with a tail of slow ones.
  3. A histogram, looking for values far from all the rest; the mean and standard deviation are affected by the outliers themselves, so they are a poor tool for finding them.