from pathlib import Path import matplotlib.pyplot as plt months = ["Jan", "Feb", "Mar", "Apr"] revenue = [42, 48, 52, 57] fig, ax = plt.subplots(layout="constrained") ax.plot(months, revenue, marker="o") ax.set_xlabel("Month", labelpad=8) ax.set_ylabel("Revenue (USD thousands)", labelpad=8) output = Path("axis-set-label.png") fig.savefig(output, dpi=150) print(f"x label: {ax.get_xlabel()}") print(f"y label: {ax.get_ylabel()}") print(f"saved: {output}")