from datetime import datetime from pathlib import Path import matplotlib.dates as mdates import matplotlib.pyplot as plt months = [datetime(2026, month, 1) for month in range(1, 13)] tickets_closed = [42, 45, 47, 51, 55, 58, 63, 61, 66, 70, 74, 79] fig, ax = plt.subplots(figsize=(7, 4), layout="constrained") ax.plot(months, tickets_closed, marker="o", linewidth=2) ax.set_title("Support tickets closed by month") ax.set_xlabel("Month closed") ax.set_ylabel("Tickets closed") ax.grid(True, axis="y", alpha=0.3) ax.set_xlim(months[0], months[-1]) locator = mdates.MonthLocator(bymonth=range(1, 13, 2)) formatter = mdates.DateFormatter("%b %Y") ax.xaxis.set_major_locator(locator) ax.xaxis.set_major_formatter(formatter) ax.tick_params(axis="x", rotation=30) fig.canvas.draw() tick_labels = [ label.get_text() for label in ax.get_xticklabels() if label.get_text() ] output = Path("support-tickets-date-axis.png") fig.savefig(output, dpi=160) print("major locator: MonthLocator(bymonth=range(1, 13, 2))") print("major formatter: DateFormatter('%b %Y')") print(f"tick labels: {', '.join(tick_labels)}") print(f"saved: {output}") print(f"bytes: {output.stat().st_size}") plt.close(fig)