from pathlib import Path import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt import pandas as pd sales = pd.DataFrame( { "quarter": ["2026 Q1", "2026 Q2", "2026 Q3", "2026 Q4"], "hardware": [18000, 21500, 23100, 26000], "software": [9500, 12000, 14800, 17100], } ) ax = sales.plot( x="quarter", y=["hardware", "software"], kind="bar", figsize=(7, 4), rot=0, title="Quarterly revenue", ) ax.set_xlabel("Quarter") ax.set_ylabel("USD") ax.legend(title="Segment") figure = ax.get_figure() figure.tight_layout() output = Path("sales-by-quarter.png") figure.savefig(output, dpi=150) plt.close(figure) print(sales.to_string(index=False)) print(f"axes: {type(ax).__name__}") print(f"title: {ax.get_title()}") print(f"saved: {output}") print(f"bytes: {output.stat().st_size}")