{"spec_id":"scatter-regression-lowess","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nscatter-regression-lowess: Scatter Plot with LOWESS Regression\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 90/100 | Updated: 2026-05-14\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport seaborn as sns\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# Okabe-Ito palette\nBRAND = \"#009E73\"  # Position 1 - scatter points\nREGRESSION = \"#C475FD\"  # Position 2 - LOWESS curve\n\n# Configure theme\nsns.set_theme(\n    style=\"ticks\",\n    rc={\n        \"figure.facecolor\": PAGE_BG,\n        \"axes.facecolor\": PAGE_BG,\n        \"axes.edgecolor\": INK_SOFT,\n        \"axes.labelcolor\": INK,\n        \"text.color\": INK,\n        \"xtick.color\": INK_SOFT,\n        \"ytick.color\": INK_SOFT,\n        \"grid.color\": INK,\n        \"grid.alpha\": 0.10,\n        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\n\n# Data - create non-linear relationship with distinct local variations\nnp.random.seed(42)\nn_points = 200\nx = np.linspace(0, 10, n_points)\n\n# Complex pattern: steep rise 0-2, plateau 2-5, sharp dip 5-6, gentle rise 6-10\ny = (\n    np.where(x < 2, 3 * x, 6)\n    + np.where((x >= 2) & (x < 5), 0, 0)\n    + np.where((x >= 5) & (x < 6), -4 * (x - 5), 0)\n    + np.where(x >= 6, 0.5 * (x - 6), 0)\n    + np.random.normal(0, 0.6, n_points)\n)\n\n# Create figure\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\n\n# Scatter plot with LOWESS regression\nsns.regplot(\n    x=x,\n    y=y,\n    lowess=True,\n    scatter_kws={\"alpha\": 0.6, \"s\": 100, \"color\": BRAND, \"edgecolors\": PAGE_BG, \"linewidths\": 0.5},\n    line_kws={\"color\": REGRESSION, \"linewidth\": 4},\n    ax=ax,\n)\n\n# Styling\nax.set_xlabel(\"Input Variable (x)\", fontsize=20, color=INK)\nax.set_ylabel(\"Response Variable (y)\", fontsize=20, color=INK)\nax.set_title(\"scatter-regression-lowess · seaborn · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\n# Remove top and right spines\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nax.spines[\"left\"].set_color(INK_SOFT)\nax.spines[\"bottom\"].set_color(INK_SOFT)\n\n# Subtle grid\nax.yaxis.grid(True, alpha=0.10, linewidth=0.8, color=INK)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}