Chapter 11 · 9 levels

Charts with pandas and matplotlib

Line, bar, histogram, scatter and stacked charts drawn with pandas and matplotlib, starting from the question and checking the numbers behind every chart.

Start

A table is something you read. A chart is something you see: a trend, a gap between two bars or a long tail jumps out in under a second. That’s why almost every analysis you hand over ends in a chart, and why this chapter is all about drawing the right one.

Every level starts from a question a colleague asks, because the question picks the chart. Change over time is a line. Comparing categories is a bar. How values spread out is a histogram. Whether two numbers move together is a scatter plot. What a total is made of is a stacked bar.

How charts work in this game. Your code runs real matplotlib in the browser. Import it with import matplotlib.pyplot as plt (keep that line: it’s what tells the page to load the chart library) and every chart you draw shows up under your result, as an image. The first chart on a visit takes a few seconds while the library loads. The check looks at the data behind the chart, which you store in result: the Series or DataFrame you plotted. A beautiful chart of the wrong numbers is still wrong, and a correct table is the part a colleague can verify. Colors, titles and labels are up to you, and the lessons show what makes a chart clear and honest.

The chapter ends with a boss level where you build a small marketing dashboard: four charts on one figure, ready to drop into a slide.

Levels

  1. Black Friday in one line

    from Megan Collins, Head of Sales

    matplotlib, line chart, fig ax, axhline, resample

    Code Difficulty 2 of 5 Not started

  2. Which return reasons cost the most?

    from Angela Rivera, Head of Customer Support

    bar chart, barh, sort values, bar label, highlight

    Code Difficulty 2 of 5 Not started

  3. The question picks the chart

    from Priya Shah, Head of Data

    chart choice, histogram, line chart, bar chart, scatter

    Quiz Difficulty 1 of 5 Not started

  4. Are most orders small?

    from Laura Bennett, Head of Finance

    histogram, bins, distribution, mean vs median, np histogram

    Code Difficulty 3 of 5 Not started

  5. Do pricier products sell fewer units?

    from Thomas Whitaker, Head of Merchandising

    scatter, polyfit, trend line, slope, alpha

    Code Difficulty 3 of 5 Not started

  6. Did orders really grow seventeen times?

    from Catherine Hale, Chief Executive Officer

    honest charts, y axis zero, set ylim, chart checklist

    Quiz Difficulty 2 of 5 Not started

  7. Is the app catching up with the website?

    from Jordan Reyes, Head of Marketing

    multi line, legend, wide table, pivot table, pandas plot

    Code Difficulty 3 of 5 Not started

  8. How the channel mix shifted

    from Robert Kim, Chief Operating Officer

    stacked bar, grouped bar, shares, crosstab, composition

    Code Difficulty 3 of 5 Not started

  9. Boss: the marketing dashboard

    from Jordan Reyes, Head of Marketing

    subplots, dashboard, line chart, bar chart, cost per conversion

    Boss · 3 steps Difficulty 4 of 5 Not started

Pick what may run on this site. You can change this any time from "Cookie settings" at the bottom of every page.