Skip to content
Aabha AI Academy
Skip to reading

Python

10 Capstone Chart

# Profile: Charts · Matplotlib. Verify these values against your Data output.
import matplotlib.pyplot as plt
categories = ["markers", "notebooks", "pens"]
revenue_cents = [1350, 3500, 1840]
fig, ax = plt.subplots(figsize=(7, 4.4))
fig.subplots_adjust(bottom=0.24, top=0.86, left=0.12, right=0.97)
currency_values = [value / 100 for value in revenue_cents]
ax.bar(categories, currency_values, color="#0d9488")
ax.set(title="Accepted-order subtotal by category (synthetic)",
       xlabel="Category", ylabel="Fictional currency units")
ax.set_ylim(0, max(1.0, max(currency_values, default=0) * 1.2))
if len(currency_values) == 0:
    ax.text(0.5, 0.5, "No accepted records", transform=ax.transAxes, ha="center")
fig.text(0.02, 0.045, "Rejected records are excluded.\nThis accepted subtotal is not a complete sales total.", fontsize=8.5)
fig.savefig("accepted_subtotal.png", dpi=160)
print(f"Accepted subtotal: {sum(revenue_cents) / 100:.2f} fictional currency units")

Download this source file