{"spec_id":"dumbbell-basic","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\ndumbbell-basic: Basic Dumbbell Chart\nLibrary: seaborn 0.13.2 | Python 3.13.14\nQuality: 87/100 | Updated: 2026-06-30\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport pandas as pd\nimport seaborn as sns\n\n\n# Theme tokens — Imprint palette\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\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\nBEFORE_COLOR = \"#009E73\"  # Imprint position 1 — first series\nAFTER_COLOR = \"#C475FD\"  # Imprint position 2\n\n# Data — page load time (seconds) before and after performance optimisation\ndf = pd.DataFrame(\n    {\n        \"Page\": [\n            \"Home\",\n            \"Product Listing\",\n            \"Search Results\",\n            \"Product Detail\",\n            \"Shopping Cart\",\n            \"Checkout\",\n            \"User Account\",\n            \"Blog Index\",\n            \"Blog Article\",\n            \"Contact Us\",\n            \"About Us\",\n            \"Order History\",\n        ],\n        \"Before\": [4.2, 6.8, 5.5, 5.1, 3.8, 4.9, 3.2, 4.5, 3.6, 2.9, 2.5, 3.9],\n        \"After\": [1.4, 2.3, 1.9, 1.7, 1.1, 1.6, 0.9, 1.5, 1.2, 0.8, 0.7, 1.3],\n    }\n)\ndf[\"Reduction\"] = df[\"Before\"] - df[\"After\"]\ndf = df.sort_values(\"Reduction\", ascending=True).reset_index(drop=True)\n\n# Theme-adaptive seaborn styling\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.12,\n        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\n\n# Canvas — landscape 3200×1800 px (8 × 4.5 in @ dpi=400)\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\n\n# Linewidth range proportional to reduction magnitude for visual hierarchy\nred_min = df[\"Reduction\"].min()\nred_max = df[\"Reduction\"].max()\n\n# Connecting lines (drawn first, sit beneath dots) — width encodes improvement magnitude\nfor i, row in df.iterrows():\n    lw = 0.8 + (row[\"Reduction\"] - red_min) / (red_max - red_min) * 1.4\n    ax.plot([row[\"Before\"], row[\"After\"]], [i, i], color=INK_SOFT, alpha=0.45, linewidth=lw, zorder=1)\n\n# Dots — seaborn scatterplot for both ends; s=150 for adequate visual weight on 3200×1800\nsns.scatterplot(\n    x=df[\"Before\"],\n    y=range(len(df)),\n    color=BEFORE_COLOR,\n    s=150,\n    label=\"Before optimisation\",\n    edgecolor=PAGE_BG,\n    linewidth=0.8,\n    ax=ax,\n    zorder=2,\n)\nsns.scatterplot(\n    x=df[\"After\"],\n    y=range(len(df)),\n    color=AFTER_COLOR,\n    s=150,\n    label=\"After optimisation\",\n    edgecolor=PAGE_BG,\n    linewidth=0.8,\n    ax=ax,\n    zorder=3,\n)\n\n# Delta annotations — reduction in seconds, positioned right of the Before dot\nfor i, row in df.iterrows():\n    ax.text(row[\"Before\"] + 0.18, i, f\"−{row['Reduction']:.1f}s\", va=\"center\", ha=\"left\", fontsize=7, color=INK_MUTED)\n\n# Axes\nax.set_yticks(range(len(df)))\nax.set_yticklabels(df[\"Page\"])\nax.set_xlabel(\"Page Load Time (seconds)\", fontsize=10, color=INK)\nax.set_ylabel(\"\", fontsize=10)\nax.set_title(\"dumbbell-basic · python · seaborn · anyplot.ai\", fontsize=12, fontweight=\"medium\", color=INK, pad=14)\nax.tick_params(axis=\"both\", labelsize=8)\nax.set_xlim(0.0, 8.5)\nax.set_ylim(-0.7, len(df) - 0.3)\n\nsns.despine(ax=ax, top=True, right=True)\nax.xaxis.grid(True, linewidth=0.6)\nax.yaxis.grid(False)\n\nlegend = ax.legend(fontsize=8, loc=\"lower right\", frameon=True, framealpha=1.0, borderpad=0.7)\nfor text in legend.get_texts():\n    text.set_color(INK)\n\nfig.subplots_adjust(left=0.18, right=0.95, top=0.93, bottom=0.12)\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\nplt.close()\n"}