Make a chart a colleague can read
Use a bar chart to compare categories, and a line chart for a time sequence. Start with a table you trust:
import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.bar(totals["team"], totals["amount"]) ax.set_title("Team spending") ax.set_xlabel("Team") ax.set_ylabel("Spend (credits)") fig.tight_layout()
plt.subplots() returns a figure (the whole image) and axes (the plotting area); fig, ax = ... unpacks them. fig.tight_layout() adjusts spacing so labels fit.
ax.plot(x, y, marker="o") draws a line instead. Sort time labels before plotting; a line connects points in the order you pass them. ISO date strings (YYYY-MM-DD) sort chronologically with bookings.sort_values("week"). Labels must explain the category, measure, and units. fig.autofmt_xdate() can rotate crowded date labels.
The runner captures open figures after your check with the noninteractive Agg backend. You do not need plt.show() or a GUI. Leave your figure open: plt.close() would remove the chart from your result. The checks inspect your chart; they do not draw it for you.
See it run
import pandas as pd parcels = pd.DataFrame({"depot": ["N", "S", "N", "S", "E"], "n": [4, 6, 5, 2, 7]}) totals = parcels.groupby("depot")["n"].sum() labels = totals.index.tolist() heights = totals.tolist()
A bar chart is just labels plus heights. Get the numbers right first.
Practice make a chart a colleague can read
Exercise 1
A distribution supervisor wants total parcels by depot. Load depot_parcels.csv as shipments, sum parcels by depot alphabetically into totals, then create one bar chart as fig, ax. Use title "Parcels by depot", x-label "Depot", y-label "Parcels". Leave the figure open.
Exercise 2
A booking coordinator needs a chronological trend, not file order. Read weekly_bookings.csv as bookings, sort by the ISO date week, and draw one line with those dates on x and bookings on y. Save fig, ax. Title: "Weekly room bookings"; x-label: "Week starting"; y-label: "Bookings". Keep all 12 points and leave the figure open.
Exercise 3
An event manager compares staffed hours by venue. Read venue_shifts.csv as shifts, convert each shift's minutes to hours, and sum hours by venue alphabetically into totals (columns venue, hours). Draw a bar chart as fig, ax titled "Staffing by venue", x-label "Venue", y-label "Hours". Leave it open.
The explanation and tasks are public. Running this lesson requires an account with course access.
Practice
Loading Python…Visualizer Watch your code run line by line
Run your code, then choose Play to follow its execution.