JIT — Intro to Data Science · Python Lab · Problem 26 of 30

The shape of a column

A histogram and a box plot of the same ten marks — and the two settings that decide whether the odd one shows up at all.

Two pictures of one column

A bar chart compares one number per category. This is a different question: you have a single column of ten marks, and you want to know what it looks like — where the students are bunched, whether anyone is stranded out on their own.

The same ten marks from problem 24: nine of them between 62 and 81, and one of 12.

New word — histogram plt.hist(marks, bins=6) chops the range into equal-width buckets and counts how many marks land in each. The height of each bar is a count of students, not a mark.
It is not a bar chart. A bar chart has one bar per named thing; a histogram has one bar per slice of the number line, and the categories did not exist until you chose how many slices to cut.
The bin count changes what you see Too few buckets and everything collapses into one lump. Too many and each student gets a bar of their own, which is the original data with extra steps. There is no correct number — it is a judgement, and the honest thing is to try two or three before deciding what the column looks like.
New word — box plot plt.boxplot(marks) draws the arithmetic you did by hand in problem 24. The box runs from Q1 to Q3, the line across it is the median, the whiskers reach out to the furthest value still inside the fences, and anything beyond them is drawn as a separate point.
That lone point is the 12. You calculated it in problem 24; here matplotlib works out the same quartiles and the same fences and draws them.
whis is the 1.5 from problem 24 plt.boxplot(marks, whis=1.5) is the default, and 1.5 is the convention you used before. Raise it and the whiskers stretch further, so fewer points fall outside and the odd mark is quietly swallowed into the normal range. Lower it and ordinary students start being flagged.
The value is yours to set, which means a box plot can be made to show an outlier or hide one. Worth knowing when reading somebody else's.
New word — subplot plt.subplot(1, 2, 1) means: one row, two columns, and I am now drawing in the first of them. Everything you plot afterwards goes into that panel until you choose another. It is how two views of the same data are put side by side for comparison.

What you are building

Two panels: the histogram on the left showing where the class bunches, the box plot on the right showing the same thing as quartiles — with the 12 marked as a point on its own.

Coming later Both of these describe one column. Problem 27 puts two columns against each other and asks whether one moves with the other.

Build the programme

Your plan

The steps still to place

The whole programme is laid out below. Four pieces are missing, and as in problem 25 not one of them will stop the programme. Two of them change what the picture appears to say.

Leave nothing on "choose…". A wrong pick does not always cause an error — sometimes it just prints something you did not expect, which is the harder kind of mistake to spot.

Run and read

Here is the whole programme. Run it, then try a different number of buckets and a different whisker setting, and watch how much the same ten marks can be made to look like.

Your programme

Output

Nothing has run yet.