Lesson

Comparing and Relating: Boxplots, Violin Plots, Scatter Plots and Frequency Tables

How to compare distributions across groups and check whether two variables are related: the boxplot and the IQR rule, the violin plot, scatter plots, frequency tables, conditional rates and independence in data, on the 2026 Stack Overflow Developer Survey.

Last updated:


In this lesson we learn to compare distributions and to check for a relation between variables:
the boxplot and the IQR rule for flagging outliers, the violin plot, comparing groups, the scatter plot for two quantitative variables, frequency tables and conditional rates for two categorical variables, and when two variables are “roughly unrelated” in the data.
We continue with the 2026 Stack Overflow Developer Survey and with the question of how much software developers earn and what is related to it.
Mean, median, quartiles, the IQR and the histogram are taught in Same Statistics, Different Pictures.

The boxplot: five numbers in one picture

A boxplot draws the quartiles of a quantitative variable in one small picture:

  • The box stretches from Q1Q_1 to Q3Q_3⁠, so its width is the IQR. A line inside the box marks the median.
  • The whiskers are lines that leave the box on both sides, up to the furthest value that is not yet flagged as an outlier.
  • Points beyond the whiskers are values flagged as outliers.

We draw a boxplot of the number of tools. The survey asked “In a typical month over the past year, about how many distinct software tools, platforms, or services did you personally use to do your primary work?”. 14,836 respondents answered, and we keep the 14,751 answers of up to 100 tools.
The quartiles: Q1=4Q_1=4⁠, median 6, Q3=10Q_3=10⁠, so IQR=6\mathrm{IQR}=6⁠. The upper whisker ends at 19, and the 1,358 answers above it are drawn as points.

Horizontal boxplot of the number of software tools developers use in a typical month. The box runs from 4 to 10 with the median at 6, the whiskers reach 0 and 19, and the larger answers form a row of separate points from 20 to 40.
The number of tools respondents use in a typical month: 14,751 answers up to 100. The axis stops at 40, so 184 larger answers are not shown. Data: Stack Overflow Developer Survey 2026, Stack Exchange, Inc., licensed under ODbL 1.0.

Try it yourself: how was it decided that the upper whisker ends at 19 and not at some other value?
Formulate a rule that decides which values are flagged as outliers, using Q1Q_1⁠, Q3Q_3 and the IQR.

Hint

How far is 19 from Q3Q_3⁠? Compare that distance with the IQR.

The formal definition

A value is flagged as an outlier if it is greater than Q3+1.5⋅IQRQ_3+1.5\cdot\mathrm{IQR} or smaller than Q1−1.5⋅IQRQ_1-1.5\cdot\mathrm{IQR}⁠.
A whisker extends to the furthest value still inside these limits.

For the number of tools: Q3+1.5⋅IQR=10+1.5⋅6=19Q_3+1.5\cdot\mathrm{IQR}=10+1.5\cdot 6=19⁠, and the lower limit 4−9=−54-9=-5 is below every possible value, so the lower whisker reaches 0.
The rule is a convention due to John Tukey: an “outlier” in this sense means “worth checking”, not “wrong”.

The violin plot: what the boxplot hides

Think: about how many distinct software tools, platforms or services do you use in a month of study and work?
Write down one number, and notice how you arrived at it.

A violin plot is a smoothed histogram drawn along the axis and mirrored on both sides:
instead of bars there is a continuous curve, and the width of the shape at each height shows how many values lie there.
The smoothing averages each point with its neighbours, so the shape does not depend on where bin edges fall.

The same tool counts twice: a boxplot (a box from 4 to 10 and a row of points) and a violin plot, whose width shows how many answers are near each value. The violin has humps at 5, 10, 15 and 20 (2,550, 2,389, 646 and 708 answers) that the boxplot does not show.
The same 14,751 answers as a boxplot and as a violin plot (the axis stops at 40, so 184 larger answers are not shown). Data: Stack Overflow Developer Survey 2026, Stack Exchange, Inc., licensed under ODbL 1.0.

The boxplot shows a box from 4 to 10 and a row of points. The violin shows humps at 5, 10, 15 and 20, with dips between them.
The box cannot show this, because it summarises all the data in five numbers.

Think: what could create humps exactly at 5, 10, 15 and 20?

Answer

The survey question asks “about how many”, and most people do not count their tools one by one; they answer with a round number.
In the data: 2,550 respondents answered 5 and 1,135 answered 6; 2,389 answered 10, while only 265 answered 9 and 114 answered 11; 708 answered 20 and only 13 answered 19.
The humps are what the data show: a distribution of people’s answers, with the human habit of rounding.
Whoever analyses these data needs to know that the difference between 19 and 20 in this column is not a real difference in the number of tools.

Check: two teams measured a server’s response times. The two boxplots are almost identical.
Does that mean the distributions are alike?

Answer

Not necessarily. A boxplot is a summary in five numbers, and two very different distributions can have the same quartiles:
one with a single hump, another with two (for example requests answered from fast memory and requests answered from disk).
A violin plot or a histogram would show the difference.

Try the tool: choose a set, and compare the boxplot with the violin plot of xx⁠.
In which sets does the violin show something that the box hides?

In the interactive version of the tool we choose a set and see it as a scatter plot, a histogram, a boxplot, and a violin plot. 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
Nine violin plots of x side by side, numbered 1 to 9, each with a boxplot inside. The boxes are very similar, and the violins of sets 3, 4, 6 and 9 have several humps.
For each set, in the order of the table rows (1 to 9), a violin plot of x with a boxplot inside. The boxes are almost the same; the violins show where the values cluster.
Answer

In the sets where the values of xx gather in several separate regions, such as the shofar, the dreidel and the Purim mask, the violin shows several humps with dips between them.
The boxes of those sets look like the box of a set with a single hump:
they show only the median, the quartiles and the whiskers, not where the values gather inside the box.
In the Star of David and the megillah the values of xx are spread roughly evenly, and the two charts tell roughly the same story.
In the map of Israel, too, the box of xx looks like the other boxes, while the violin shows three humps:
the boat and the waves in the sea to the west, the map in the middle and the compass rose to the east.

Comparing groups: salary by experience

Boxplots and violin plots are especially handy for comparison:
draw one per group, side by side, on the same axis. We split respondents into four groups by years of professional experience (up to 4, 5-9, 10-19, and 20 or more) and draw the salary in each group on a log scale.
As in Same Statistics, Different Pictures, we keep salaries between 1,000 and 1,000,000 dollars.

Salary on a logarithmic axis for four groups of work experience, each drawn as a violin with a small boxplot inside. The median rises with experience: 37,530 dollars for up to 4 years, 65,733 for 5-9, 93,363 for 10-19 and 106,371 for 20 years or more; the groups still overlap widely.
Annual salary (logarithmic axis) of 12,873 respondents by experience group. Each violin has a white box from the first to the third quartile, with a line at the median. Data: Stack Overflow Developer Survey 2026, Stack Exchange, Inc., licensed under ODbL 1.0.
Years of experienceRespondentsQ1Q_1MedianQ3Q_3
up to 41,97014,19537,53065,000
5-92,55837,35965,733100,000
10-194,46760,16293,363139,647
20+3,87869,626106,371160,000

What the comparison shows:

  • The centre rises with experience: the median rises from 37,530 to 106,371 dollars.
  • The rise slows down: from the first group to the second the median almost doubles, and from the third to the fourth it rises by about 14%.
  • The groups overlap: the boxes of neighbouring groups overlap, so many respondents with little experience earn more than experienced ones.
  • The first group is especially spread out: its violin reaches deep into salaries of a few thousand dollars.

Check: do the data show that more years of experience cause a higher salary?

Answer

No. The data show that salaries are higher in the more experienced groups, but the comparison is between different people, not the same people followed over time.
Experienced respondents also differ in other ways: age, role, country, field.
The survey describes a relation; it does not show what causes what.

Boxplots and violin plots in matplotlib

  • plt.boxplot(groups) draws one boxplot for each list of values in the list groups.
  • plt.violinplot(groups) draws a violin for each list; showmedians=True adds a line at the median.
  • pd.cut(values, bins, labels) splits a quantitative variable into intervals and returns, for each row, the name of its interval.
  • df[df[‘band’] == b] keeps only the rows of one group. This is how we build a list of arrays, one array per group.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('so-2026-week1.csv')
d = df[(df['salary_usd'] >= 1000) & (df['salary_usd'] < 1000000)].copy()
median_all = d['salary_usd'].median()
labels = ['up to 4', '5-9', '10-19', '20+']
d['band'] = pd.cut(d['work_exp'], [-1, 4, 9, 19, 100], labels=labels)
d = d.dropna(subset=['band'])
groups = [np.log10(d[d['band'] == b]['salary_usd']) for b in labels]
plt.violinplot(groups, showmedians=True)
plt.xticks([1, 2, 3, 4], labels)
plt.show()
Four violin plots of the base-10 logarithm of salary by years of experience (up to 4, 5-9, 10-19, 20+): the median line rises from group to group, and the first violin reaches furthest down, to salaries of a few thousand dollars.

What does this program compute?

for b in labels:
    print(b, d[d['band'] == b]['salary_usd'].median())
Answer

For each of the four experience groups the program prints the group’s name and the median salary in it:
the numbers in the median column of the table above. The median is computed on the salary itself, not on its logarithm; because the order does not change, in data this large the median of the logarithms is in practice the logarithm of the median (exactly so when the number of values is odd).

Scatter plots: experience and salary

To see the relation between two quantitative variables we draw a scatter plot:
each respondent is a point, the horizontal position is their years of experience and the height is their salary.
Unlike the comparison of four groups, here experience is not cut into intervals.

Scatter plot of 2,000 respondents: years of work experience across and salary up, on a logarithmic axis. The cloud rises from left to right, quickly in the first ten years and slowly afterwards, and it is wide: at every experience level salaries range over more than a factor of ten.
Each dot is a respondent: years of experience across and annual salary up (logarithmic axis). A random sample of 2,000 of 12,873 respondents (seed 2026), drawn semi-transparent; 7 dots above 50 years lie outside the chart. Data: Stack Overflow Developer Survey 2026, Stack Exchange, Inc., licensed under ODbL 1.0.

Three questions help to read a scatter plot:

  • Direction: do the points rise or fall from left to right? Here they rise: the more experience, the higher the salary tends to be.
  • Form: is the rise straight, or does it bend? Here it is steep in the first years and then levels off: the median for respondents with one year is 29,456 dollars, with 10 years 82,065, with 20 years 98,916 and with 30 years 103,869.
  • Strength: how tightly does the cloud follow a line? Here the cloud is very wide: at every level of experience there are respondents earning thousands and respondents earning hundreds of thousands. The relation exists, but it is fairly weak.

Check: many points in the chart are drawn on top of each other, mostly at whole numbers of years.
How can that mislead, and what did we do in the chart to reduce the problem?

Answer

When many points fall in the same place they look like a single point, and dense regions look sparser than they are.
In the chart the points are semi-transparent, so a dense region looks darker.
One can also draw only a sample of the points, or move each point by a small random horizontal amount so that they do not fall exactly on top of each other; when doing so, say it in the caption.

Frequency tables: experience and salary above the median

When the variables are categorical there is no scatter plot.
We count how many observations have each combination of values, and arrange the counts in a frequency table.
To ask the salary question this way, we turn both variables into categories:
experience into the four groups, and salary into two, above the median of all respondents (81,884 dollars) or below it.
Turning a quantitative variable into categories loses information, but lets us answer with a simple table.

Years of experienceAbove the medianBelow the medianTotal
up to 43121,6581,970
5-99161,6422,558
10-192,6511,8164,467
20+2,5961,2823,878
Total6,4756,39812,873
  • Joint frequency: the number in a cell, for example 312 respondents who have up to 4 years of experience and a salary above the median.
  • Marginal frequency: the totals in the margins, for example 1,970 respondents with up to 4 years of experience, whatever their salary.

Rows with different numbers of respondents are hard to compare (1,970 against 4,467).
So we divide each cell by the total of its row and get the conditional rate by row:
of the respondents in the row, which share falls in each column.

Years of experienceAbove the medianBelow the median
up to 415.8%84.2%
5-935.8%64.2%
10-1959.3%40.7%
20+66.9%33.1%

The conditional rate of “above the median” varies a lot between rows:
from 15.8% to 66.9%. So the distribution of salary (above or below) depends on the experience group.
This is the conclusion the boxplot comparison showed, now in numbers.

Check: what share of all respondents is above the median, and why is it almost exactly 50%?

Answer

6,47512,873≈50.3%\frac{6{,}475}{12{,}873}\approx 50.3\%⁠. The median is defined so that half of the values are above it and half below; the small difference from 50% comes from the median being computed on all 12,969 respondents with a salary, including those who did not answer the experience question, and from respondents whose salary equals the median exactly being counted as “above”.

Frequency tables in pandas

  • np.where(condition, x, y) returns x for each row where the condition holds and y where it does not.
  • pd.crosstab(a, b) returns a frequency table: a row for each value of a, a column for each value of b, and in each cell the number of rows with that combination.
  • normalize=‘index’ divides each cell by the total of its row and returns conditional rates by row. margins=True adds a total row and column.
d['above'] = np.where(d['salary_usd'] >= median_all, 'above', 'below')
print(pd.crosstab(d['band'], d['above'], margins=True))
print(pd.crosstab(d['band'], d['above'], normalize='index').round(3))
above    above  below    All
band                        
up to 4    312   1658   1970
5-9        916   1642   2558
10-19     2651   1816   4467
20+       2596   1282   3878
All       6475   6398  12873
above    above  below
band                 
up to 4  0.158  0.842
5-9      0.358  0.642
10-19    0.593  0.407
20+      0.669  0.331

What does this program compute?

t = pd.crosstab(d['band'], d['above'], normalize='columns')
print(t.round(3))
Answer

With normalize=‘columns’ each cell is divided by the total of its column.
The result answers a different question: of the respondents above the median, which share is in each experience group.
For example, the share of the up-to-4 group in the “above” column is 3126,475≈4.8%\frac{312}{6{,}475}\approx 4.8\%⁠.
That is not the rate of “above the median” within the experience group (15.8%); the direction must match the question.

Independence in data: organisation size and AI use

Now a different question from the survey: do people working in large organisations use AI tools more or less than people in small ones?
We use the question “Do you currently use AI tools or AI agents in your role at work?”:
“No” means respondents who chose only the option that they do not use AI tools, and “Yes” means respondents who chose some tool.

Organisation size (employees)RespondentsDo not useUse
fewer than 202,37113.5%86.5%
20-4994,99212.4%87.6%
500-4,9992,60811.9%88.1%
5,000 or more2,85012.2%87.8%

Try it yourself: compare this table with the table of experience and salary.
Put into words: when would we say that two variables are “roughly unrelated” in the data?

Hint

Look at the conditional rate of “do not use” in each row. How much does it vary between rows, and how much did the rate of “above the median” vary in the experience table?

The formal definition

The joint distribution of two categorical variables is the share of each combination of values among all observations (each cell of the frequency table divided by the total).
We say that two variables are independent in the data when the conditional rates by row are almost the same in every row:
the distribution of one variable hardly changes when the value of the other changes.

Here the rate of “do not use” ranges from 11.9% to 13.5% (a difference of 1.6 percentage points), so organisation size and AI use are roughly unrelated in these data.
In the experience table the rate of “above the median” ranges from 15.8% to 66.9%, and there the variables are clearly dependent.
This is independence in data: it describes the table in front of us, and “almost the same” is a judgement worth supporting with numbers.

Check: the survey’s organisation-size question also has the categories “Just me (self-employed)” and “I don’t know”.
Among “Just me” 20.1% do not use AI tools, and among “I don’t know” 30.7%.
Do the variables still look independent?

Answer

No. With these two categories the conditional rate of “do not use” ranges from 11.9% to 30.7%, so there is a relation.
How we decide which categories enter the table changes the conclusion, so we also report which categories were included.
The “I don’t know” group may differ in something else, for example by including more respondents who do not work in an ordinary organisation.

What we found out about salary

Back to the question that has run through the week: how much do software developers earn, and what is related to it?

  • Typical salary: the median in the survey is 81,884 dollars a year, and the mean is higher (99,020) because of a right tail of high salaries. Half of the respondents earn between about 46 thousand and 130 thousand.
  • Shape: on a log scale salaries spread over a thousandfold range, from a few thousand to hundreds of thousands.
  • Experience: salaries are higher in more experienced groups, especially over the first ten years, but the groups overlap a lot.
  • What we did not see: cause and effect, and the people who did not answer: 56% of respondents gave no salary, and the survey describes only those who chose to take part.

From data to a decision: a salary offer

People who receive a job offer have to decide whether to accept the salary offered or ask for more.
The analysis we did this week helps to decide.

Think: two offers of an annual salary, in dollars:

  1. 60,000 dollars for a position that requires 3 years of experience.
  2. 70,000 dollars for a position that requires 15 years of experience.

According to the survey, which offer is higher than most comparable offers, and in which is there a basis for asking for more?
How can a comparison with the median of all respondents (81,884 dollars) mislead here?

Hint

Use the table of quartiles by experience, and find the group of each offer.

Answer
  1. 3 years of experience belong to the group “up to 4”: Q1=14,195Q_1=14{,}195⁠, median 37,530 and Q3=65,000Q_3=65{,}000⁠. The offer is above the median and close to Q3Q_3⁠: 71.0% of the respondents in the group earn less than 60,000. This offer is higher than most comparable offers. Compared with the median of all respondents it looks low.
  2. 15 years of experience belong to the group “10 to 19”: Q1=60,162Q_1=60{,}162 and median 93,363. The offer lies between Q1Q_1 and the median: only 31.9% of the respondents in the group earn less than 70,000, so more than two thirds earn more. There is a basis for asking for more. Compared with the median of all respondents the gap looks small (about 12 thousand); within the group it is about 23 thousand.

For the first offer the comparison with the median of all respondents leads to the opposite decision; for the second it shrinks the gap.
The median of all respondents mixes all experience groups, and the frequency table showed that salary depends on experience.
So an offer is compared with a similar group. The groups here are wide (“up to 4” also includes respondents with no experience), and the survey describes salaries, not offers, so this is an estimate, not an exact price.
We compare it with the median and the quartiles, not the mean:
the question is where the offer stands among comparable offers, and the right tail pulls the mean up.

What these data are not enough to decide: the survey converts salaries to dollars at the exchange rate, with no adjustment for the cost of living, and mixes respondents from every country.
Only 89 respondents from Israel gave a salary, and their median is 163,287 dollars, about twice the median of all respondents.
So the country is also part of a “similar group”. For an offer in Israel the survey is not enough:
89 respondents who chose to answer are a small group, and we do not know how well they represent Israeli developers.
The practical decision is to look for another source, such as an Israeli salary survey, and to compare within a similar group there too.

What do we do from now on before any analysis? What we did with the four datasets at the start of the week and with salary:

  1. Look at the data in a chart: a histogram or a violin plot for one variable, a scatter plot for two.
  2. Decide what to do with missing and implausible values, and write the decision down.
  3. Choose a statistic that suits the shape: the median and the IQR when there is a tail or outliers.
  4. Compare groups on the same axis, and check for a relation with conditional rates, not raw counts.

Think: a software company announces that “developers who use AI tools earn 10% more on average”.
Which two questions would you ask before concluding anything?

A possible answer
  1. Mean or median? With a right tail, a few very high salaries in one group can create a difference in the mean without most people in it earning more.
  2. Are the groups alike in other ways, such as experience, country and role? If AI users are more experienced or work in higher-paying countries, the difference may come from that. Comparing within similar groups (for example within one experience group) is a first step towards checking.