{"spec_id":"polar-bar","library":"letsplot","language":"python","code":"\"\"\" anyplot.ai\npolar-bar: Polar Bar Chart (Wind Rose)\nLibrary: letsplot 4.9.0 | Python 3.13.13\nQuality: 92/100 | Updated: 2026-05-13\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom lets_plot import (\n    LetsPlot,\n    aes,\n    coord_polar,\n    element_line,\n    element_rect,\n    element_text,\n    geom_bar,\n    ggplot,\n    ggsave,\n    ggsize,\n    labs,\n    scale_fill_manual,\n    scale_y_continuous,\n    theme,\n    theme_minimal,\n)\n\n\nLetsPlot.setup_html()\n\n# Theme-adaptive colors\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# Okabe-Ito palette + adaptive neutral for 8 compass directions\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\"]\nNEUTRAL = \"#1A1A1A\" if THEME == \"light\" else \"#E8E8E0\"\nDIRECTION_COLORS = IMPRINT + [NEUTRAL]\n\n# Data - Monsoon wind pattern (SW-dominant, distinct from westerlies)\ndirections = [\"N\", \"NE\", \"E\", \"SE\", \"S\", \"SW\", \"W\", \"NW\"]\nfrequencies = np.array([3, 5, 6, 12, 28, 35, 6, 5])\n\n# Create DataFrame\ndf = pd.DataFrame(\n    {\"direction\": pd.Categorical(directions, categories=directions, ordered=True), \"frequency\": frequencies}\n)\n\n# Create polar bar chart (wind rose)\nplot = (\n    ggplot(df, aes(x=\"direction\", y=\"frequency\", fill=\"direction\"))\n    + geom_bar(stat=\"identity\", color=\"white\", size=0.5, alpha=0.85, width=0.95)\n    + coord_polar(start=-np.pi / 8)\n    + scale_fill_manual(values=DIRECTION_COLORS)\n    + scale_y_continuous(limits=[0, None], expand=[0, 0.5])\n    + labs(title=\"polar-bar · letsplot · anyplot.ai\", x=\"\", y=\"Frequency (%)\")\n    + theme_minimal()\n    + theme(\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_grid_major=element_line(color=INK_SOFT, size=0.3),\n        plot_title=element_text(size=24, color=INK, face=\"bold\"),\n        axis_title_y=element_text(size=20, color=INK),\n        axis_text=element_text(size=16, color=INK_SOFT),\n        legend_position=\"none\",\n    )\n    + ggsize(1200, 1200)\n)\n\n# Save as PNG and HTML (theme-suffixed)\nggsave(plot, f\"plot-{THEME}.png\", scale=3, path=\".\")\nggsave(plot, f\"plot-{THEME}.html\", path=\".\")\n"}