from pathlib import Path import matplotlib.pyplot as plt ad_spend = [120, 180, 240, 310, 380, 440, 520, 600] sales = [980, 1250, 1420, 1680, 1890, 2100, 2380, 2650] conversion_rate = [2.1, 2.4, 2.8, 3.0, 3.2, 3.4, 3.7, 3.9] orders = [24, 31, 35, 42, 48, 54, 61, 68] marker_size = [order * 6 for order in orders] fig, ax = plt.subplots(layout="constrained") scatter = ax.scatter( ad_spend, sales, c=conversion_rate, s=marker_size, cmap="viridis", alpha=0.85, edgecolors="black", linewidths=0.5, ) colorbar = fig.colorbar(scatter, ax=ax, label="Conversion rate (%)") ax.set_title("Ad spend compared with daily sales") ax.set_xlabel("Ad spend (USD)") ax.set_ylabel("Sales (USD)") ax.grid(True, alpha=0.25) output = Path("campaign-scatter-plot.png") fig.savefig(output, dpi=160) plt.close(fig) print(f"points: {len(ad_spend)}") print(f"title: {ax.get_title()}") print(f"x label: {ax.get_xlabel()}") print(f"y label: {ax.get_ylabel()}") print(f"colorbar label: {colorbar.ax.get_ylabel()}") print(f"saved: {output}") print(f"bytes: {output.stat().st_size}")