from pathlib import Path import matplotlib.pyplot as plt channels = ["Web", "Retail", "Partner", "Renewal"] revenue = [78, 64, 52, 41] fig, ax = plt.subplots(figsize=(7, 4.2), layout="constrained") ax.bar(channels, revenue, color=["#4C78A8", "#59A14F", "#F28E2B", "#B07AA1"]) ax.set_ylabel("Revenue ($k)") title = ax.set_title( "Monthly revenue by channel", loc="left", pad=14, fontweight="bold", ) figure_title = fig.suptitle("Revenue dashboard", x=0.02, ha="left", fontsize=12) output = Path("monthly-revenue-title.png") fig.savefig(output, dpi=160) plt.close(fig) print(f"axes title: {ax.get_title(loc='left')}") print(f"axes title alignment: {title.get_ha()}") print(f"figure title: {figure_title.get_text()}") print(f"saved: {output}") print(f"bytes: {output.stat().st_size}")