WeCodeAcademy

Bar Charts

A bar chart compares amounts across separate categories, such as regions, products or classes. ax.bar(names, heights) draws vertical bars. When the names are long, ax.barh(names, widths) draws horizontal bars so the labels stay readable.

Bar length is the message, so always start the value axis at zero (the lesson on honest charts explains why). Sorting the bars from largest to smallest usually makes the ranking obvious at a glance.

Examplepython
Open in editor »
Quick check

Which call draws horizontal bars?

Your turn: write the code

Draw the bars and print the height of each bar as a list of whole numbers (use [int(p.get_height()) for p in ax.patches]).

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.