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

Sales by city, as a chart

Five numbers made into a picture — and five ways to draw a picture that looks right and says nothing.

A picture of five numbers

The table of sales has five rows. You can read it. But a reader wants to know which city is ahead and by how much, and a picture answers that in a second where a table takes ten.

New words — pyplot and bar import matplotlib.pyplot as plt — the same shape of line as pandas, with plt as the nickname everybody uses.
plt.bar(x, heights) takes two things: what goes along the bottom, and how tall each bar should be. One bar per entry, in the order they appear.
Matplotlib will draw almost anything you ask for Hand it the wrong column and it does not complain — it draws a chart. Hand it text where the heights should be and it still draws a chart, using the position of each category as the height. Hand it one number for five bars and it draws five bars of equal height.
Nothing in this problem will stop the programme. Every wrong choice produces a picture that looks like a real chart, which is precisely why charts mislead so easily. Read the axis labels and the bar heights, every time, including on your own work.
A chart with no labels is not finished plt.title(...) says what the chart is about.
plt.xlabel(...) and plt.ylabel(...) say what each axis measures, and in what units. "Sales" is not a unit; "Sales (lakh rupees)" is.
The bars themselves carry no units at all. A reader who cannot tell whether 391 means rupees, lakhs or cartons has been given a decoration rather than a chart.
New word — show plt.show() puts the figure on screen. Until you call it, matplotlib has been building the chart quietly in memory and nothing has appeared.
A programme that draws a perfect chart and never calls plt.show() runs without error and displays nothing. If you are sure your plotting code is right and no window has opened, this is almost always why.

The file you are given

city,sales Nagpur,182 Pune,246 Mumbai,391 Nashik,128 Amravati,97
Coming later A bar chart compares one number per category. Problem 26 asks a different question — how a single column is spread out — and answers it with a histogram and the box plot whose arithmetic you did in problem 24.

Build the programme

Your plan

The steps still to place

The whole programme is laid out below. Five pieces are missing, and not one of them can stop the programme. Every combination draws something; only one combination draws the chart you were asked for.

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. Press run and the figure appears underneath, exactly as your choices describe it. Check the bar heights against the file above before you believe anything.

Your programme

Output

Nothing has run yet.