{"spec_id":"polar-bar","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\npolar-bar: Polar Bar Chart (Wind Rose)\nLibrary: pygal 3.1.0 | Python 3.13.13\nQuality: 96/100 | Updated: 2026-05-13\n\"\"\"\n\nimport os\n\nimport pygal\nfrom pygal.style import Style\n\n\n# Theme-adaptive colors (see prompts/default-style-guide.md)\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 (first series always #009E73)\nIMPRINT = (\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\")\n\n# Wind direction and frequency data\ndirections = [\"N\", \"NE\", \"E\", \"SE\", \"S\", \"SW\", \"W\", \"NW\"]\n\n# Wind speed categories (realistic meteorological data showing westerly dominance)\ncalm_winds = [8, 5, 4, 3, 5, 7, 12, 11]  # 0-5 km/h\nlight_winds = [6, 4, 3, 2, 4, 7, 10, 9]  # 5-15 km/h\nmoderate_winds = [3, 2, 2, 1, 2, 4, 7, 6]  # 15-25 km/h\nstrong_winds = [2, 1, 1, 1, 1, 2, 4, 3]  # 25+ km/h\n\n# Create custom style with theme-adaptive colors\ncustom_style = Style(\n    background=PAGE_BG,\n    plot_background=PAGE_BG,\n    foreground=INK,\n    foreground_strong=INK,\n    foreground_subtle=INK_SOFT,\n    colors=IMPRINT,\n    title_font_size=28,\n    label_font_size=22,\n    major_label_font_size=18,\n    legend_font_size=16,\n    value_font_size=14,\n    stroke_width=3,\n    opacity=0.85,\n)\n\n# Create radar chart (pygal's polar visualization for wind rose)\nchart = pygal.Radar(\n    width=4800,\n    height=2700,\n    style=custom_style,\n    title=\"Wind Rose · Wind Frequency (%) by Direction · polar-bar · pygal · pyplots.ai\",\n    show_legend=True,\n    legend_at_bottom=True,\n    legend_at_bottom_columns=4,\n    fill=True,\n    stroke=True,\n    show_dots=False,\n    range=(0, 15),\n    inner_radius=0.12,\n    margin=100,\n    spacing=50,\n)\n\n# X-axis labels (compass directions)\nchart.x_labels = directions\n\n# Add wind speed categories (layered from calm to strong)\nchart.add(\"Calm (0-5 km/h)\", calm_winds)\nchart.add(\"Light (5-15 km/h)\", light_winds)\nchart.add(\"Moderate (15-25 km/h)\", moderate_winds)\nchart.add(\"Strong (25+ km/h)\", strong_winds)\n\n# Save outputs\nchart.render_to_png(f\"plot-{THEME}.png\")\nwith open(f\"plot-{THEME}.html\", \"wb\") as f:\n    f.write(chart.render())\n"}