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:
The second is
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?
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.
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.
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
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.
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?
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.
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.