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", ) output = Path("monthly-revenue-title.png") fig.savefig(output, dpi=160) print(f"title: {ax.get_title(loc='left')}") print(f"alignment: {title.get_ha()}") print(f"saved: {output}") print(f"bytes: {output.stat().st_size}") plt.close(fig)