An old style name, a cut-off axis, and a missing unit in an AI draft
Code review · Medium · §7.4 Reusing styles and reviewing AI drafts
This is a draft you got after asking an AI: "Using the recycling pickup records (one row = one week and one material, weight in kg), compare the total weight collected for each material over weeks 1 to 4 with bars. Start the bars at 0, make the y-axis 0 to 400 kg, put the unit kg in the y-axis label, and add value labels above the bars."
The draft stops with an error when you run it. Even after you fix the error, some parts still do not match the request. Compare the request with the code line by line and fix three lines. Write the y-axis label as Weight (kg).

Code to fix
import matplotlib.pyplot as plt
import pandas as pd
weeks = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]
materials = ["Glass", "Paper", "Plastic"] * 4
weights = [42, 85, 60, 38, 90, 64, 45, 78, 70, 40, 88, 66]
pickups = pd.DataFrame({"week": weeks, "material": materials, "weight": weights})
plt.style.use("seaborn")
totals = pickups.groupby("material")["weight"].sum()
fig, ax = plt.subplots()
bars = ax.bar(totals.index, totals.values)
ax.bar_label(bars)
ax.set_ylim(150, 360)
ax.set_title("Total weight by material, weeks 1-4")
ax.set_ylabel("Weight")
plt.show()Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.