{"spec_id":"bar-basic","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nbar-basic: Basic Bar Chart\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 89/100 | Updated: 2026-05-28\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport matplotlib.ticker as ticker\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\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\nBRAND = \"#009E73\"\n\n# Data — Q1 retail sales by product department\ncategories = [\"Electronics\", \"Clothing\", \"Home & Garden\", \"Sports\", \"Books\", \"Toys\", \"Beauty\"]\nvalues = [48500, 32800, 27300, 35600, 15400, 21700, 29100]\n\nmax_idx = values.index(max(values))\nmin_idx = values.index(min(values))\n\n# Plot\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\nbars = ax.bar(categories, values, color=BRAND, width=0.65, edgecolor=PAGE_BG, linewidth=0.5)\n\n# Focal emphasis: top bar at full opacity, others desaturated\nfor i, bar in enumerate(bars):\n    bar.set_alpha(1.0 if i == max_idx else 0.55)\n\n# Value labels above bars\nax.bar_label(bars, labels=[f\"${v:,.0f}\" for v in values], padding=6, fontsize=8, color=INK_SOFT)\n\n# Y-axis dollar formatting\nax.yaxis.set_major_formatter(ticker.StrMethodFormatter(\"${x:,.0f}\"))\n\n# Title and axis labels\ntitle = \"bar-basic · python · matplotlib · anyplot.ai\"\nax.set_title(title, fontsize=12, fontweight=\"medium\", color=INK, pad=12)\nax.set_xlabel(\"Product Department\", fontsize=10, color=INK)\nax.set_ylabel(\"Sales (USD)\", fontsize=10, color=INK)\nax.tick_params(axis=\"both\", labelsize=8, colors=INK_SOFT)\nax.tick_params(axis=\"x\", length=0)\n\n# Subtle y-axis grid\nax.yaxis.grid(True, alpha=0.15, linewidth=0.8, color=INK)\nax.set_axisbelow(True)\n\n# Y-axis range with headroom for value labels and annotations\nax.set_ylim(bottom=0, top=max(values) * 1.30)\n\n# Spines — open x-axis (bottom removed; tick marks already length=0), left spine only\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nax.spines[\"bottom\"].set_visible(False)\nax.spines[\"left\"].set_color(INK_SOFT)\n\n# Annotation — top performer: text placed to the right of its bar, short arrow\nax.annotate(\n    f\"Top: {categories[max_idx]}\",\n    xy=(max_idx, values[max_idx]),\n    xytext=(max_idx + 0.55, values[max_idx] * 0.82),\n    fontsize=8,\n    fontweight=\"bold\",\n    color=BRAND,\n    ha=\"left\",\n    arrowprops={\"arrowstyle\": \"-|>\", \"color\": BRAND, \"lw\": 1.2},\n    bbox={\"facecolor\": ELEVATED_BG, \"edgecolor\": \"none\", \"alpha\": 0.75, \"pad\": 3},\n)\n\n# Annotation — lowest performer: text placed directly above its own bar (no cross-bar arrow)\nax.annotate(\n    f\"Lowest: {categories[min_idx]}\",\n    xy=(min_idx, values[min_idx]),\n    xytext=(min_idx + 0.4, values[min_idx] + max(values) * 0.20),\n    fontsize=8,\n    fontstyle=\"italic\",\n    color=INK_MUTED,\n    ha=\"left\",\n    va=\"bottom\",\n    arrowprops={\"arrowstyle\": \"-|>\", \"color\": INK_MUTED, \"lw\": 1.0},\n    bbox={\"facecolor\": ELEVATED_BG, \"edgecolor\": \"none\", \"alpha\": 0.75, \"pad\": 3},\n)\n\n# Layout\nfig.subplots_adjust(left=0.10, right=0.97, top=0.92, bottom=0.12)\n\n# Save\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}