Compare Categories with Bars

Compare a few named magnitudes without drawing a continuous path between categories or exaggerating their difference with a truncated baseline.

A line connects ordered observations. Sensor names pose a different question: how do a few category values compare? A bar plot preserves category identity without drawing a path from one sensor to another.

Compute the Height of Every Bar

Begin with the fixed calibrated table:

The result is:

[[ 2.  6.]
 [ 3.  8.]
 [ 4. 10.]]

To compare sensors, calculate one mean for each sensor column:

[3. 8.]
(2,)

The first height can be checked by hand:

2+3+43=3.\frac{2 + 3 + 4}{3} = 3.

The second is

6+8+103=8.\frac{6 + 8 + 10}{3} = 8.

The order of sensor_names must match the order of sensor_means: North first, West second. A bar plot cannot discover or repair a label-value mismatch.

Q1. Match category names to mean values

The table columns are ordered North, West. Which labelled means are correct?

Choose one

Select one choice, then check.

HintFollow one column at a time

North contains 2, 3, and 4. West contains 6, 8, and 10.

SolutionThe sensor means are 3 and 8

North has mean (2 + 3 + 4) / 3 = 3. West has mean (6 + 8 + 10) / 3 = 8. The labelled pair is North 3.0, West 8.0.

Not attempted
Review

Not marked done.

Draw Bars from a Zero Baseline

The category name supplies each horizontal position, and its mean supplies the bar height:

Compare mean calibrated readings by sensor

Two bars begin at zero and preserve the North, West category order. Printed means provide the exact values behind their heights.

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

Bars encode magnitude through length. For positive values such as 3 and 8, the usual comparison begins at zero so their full lengths share the same reference. ax.set_ylim(bottom=0) makes that choice explicit.

The horizontal positions are categories, not measurements on a continuous number line. North appearing before West records the chosen order. It does not claim that one sensor leads continuously into the other.

We retain the table's North, West order because it matches the data contract. Another question might justify alphabetical order or a documented operational order. Sorting by height is not automatically clearer: it changes the category order and can make repeated comparisons harder when other figures preserve the original sensor positions.

Q2. Build a labelled zero-baseline bar plot

Complete the bar plot for the two named sensor means. Preserve the supplied category order and make the zero baseline explicit.

Editable Python

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

HintUse names as positions and means as heights

Create fig, ax, call ax.bar(sensor_names, sensor_means), set ax.set_ylim(bottom=0), and add an x-label, y-label, and title.

SolutionDraw both bars from zero

The bar heights remain 3.0 and 8.0, in North, West order.

Not attempted
Review

Not marked done.

Check Whether the Scale Distorts the Comparison

Consider a second version of the same bar plot:

The North bar would show only the portion from 2.5 to 3.0, while the West bar would show the portion from 2.5 to 8.0. The displayed lengths would no longer represent the full magnitudes from a common zero. The values have not changed, but the visual comparison has become exaggerated.

A non-zero baseline can be appropriate for another kind of mark or a carefully explained deviation question. For ordinary positive bars whose length represents magnitude, use zero unless the question gives a clear reason not to. Always inspect the axis limits rather than assuming the visible frame begins at zero.

Q3. Diagnose a misleading baseline

Two positive bars have exact values 3 and 8, but the vertical axis begins at 2.5. What is the main problem?

Choose one

Select one choice, then check.

HintCompare full length with visible length

The values are still 3 and 8. Ask where each bar begins and which part of its magnitude the viewer can see.

SolutionThe scale exaggerates the difference

Starting at 2.5 shows lengths of only 0.5 and 5.5. Those visible lengths do not represent the full magnitudes 3 and 8 from zero, so the comparison appears more extreme than it is.

Not attempted
Review

Not marked done.

A bar plot compares magnitudes attached to named categories. Compute and check each height, keep labels aligned with their values, choose category order deliberately, and normally begin positive magnitude bars at zero. The next lesson preserves a different relationship: which two values came from the same observation.

Pause and reflect

In your own words, note what you understood, what remains unclear, or what you want to revisit. The note stays with this lesson.

0 of 3 exercises marked done

Review

Not marked done.