Section 1 - Instruction

Let's create our first plot: a bar chart. Bar charts are perfect for comparing values across different groups or categories, like sales figures for different products.

Engagement Message

What's a comparison from your daily life that would make a clear bar chart?

Section 2 - Instruction

To build a bar chart, you need your data organized into two lists. One list for your categories (the labels for each bar) and a second list for the matching numerical values (the height of each bar). The order must match!

Engagement Message

What two lists would you need to chart the number of books read each month?

Section 3 - Instruction

In Matplotlib, we use the ax.bar() method to create a bar chart. You provide your list of categories for the x-axis and your list of values for the y-axis.

ax.bar(category_list, value_list)

The library handles all the drawing for you.

Engagement Message

Makes sense?

Section 4 - Instruction

Let's see the full code. First, we prepare our data lists. Then, we create our plot and use ax.bar() to draw the bars.

Engagement Message

What categories and values would you use if you wanted to make a bar chart about your favorite snacks?

Section 5 - Instruction

Here is the bar chart created by that code. Notice how each product on the x-axis has a bar whose height corresponds to its sales value on the y-axis. This makes comparing them instant.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal