{"spec_id":"polar-bar","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\npolar-bar: Polar Bar Chart (Wind Rose)\nLibrary: plotly 6.7.0 | Python 3.13.13\nQuality: 88/100 | Updated: 2026-05-13\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport plotly.graph_objects as go\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\"\nGRID = \"rgba(26,26,23,0.10)\" if THEME == \"light\" else \"rgba(240,239,232,0.10)\"\n\n# Okabe-Ito palette (first series always #009E73)\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\"]\nwind_speed_labels = [\"Light (0-10 km/h)\", \"Moderate (10-20 km/h)\", \"Strong (20+ km/h)\"]\n\n# Data: Wind speed distribution by direction (8 compass points)\nnp.random.seed(42)\ndirections = [\"N\", \"NE\", \"E\", \"SE\", \"S\", \"SW\", \"W\", \"NW\"]\n\n# Wind speed frequencies by direction (coastal wind pattern)\nlight = np.array([8, 5, 4, 3, 6, 12, 15, 10])\nmoderate = np.array([6, 4, 3, 2, 4, 10, 12, 8])\nstrong = np.array([3, 2, 1, 1, 2, 5, 6, 4])\n\n# Create figure with polar subplot\nfig = go.Figure()\n\n# Add stacked bars for each wind speed category\nfor data, label, color in zip([light, moderate, strong], wind_speed_labels, IMPRINT, strict=True):\n    fig.add_trace(\n        go.Barpolar(\n            r=data,\n            theta=directions,\n            name=label,\n            marker=dict(color=color, line=dict(color=PAGE_BG, width=2)),\n            hovertemplate=\"<b>%{theta}</b><br>%{customdata}<br>Frequency: %{r}<extra></extra>\",\n            customdata=[label] * len(directions),\n            opacity=0.9,\n        )\n    )\n\n# Update layout for polar chart with theme-adaptive styling\nfig.update_layout(\n    title=dict(text=\"polar-bar · plotly · anyplot.ai\", font=dict(size=28, color=INK), x=0.5, xanchor=\"center\"),\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    polar=dict(\n        barmode=\"stack\",\n        radialaxis=dict(\n            visible=True,\n            range=[0, max(light + moderate + strong) + 3],\n            tickfont=dict(size=18, color=INK_SOFT),\n            gridcolor=GRID,\n            linecolor=INK_SOFT,\n            title=dict(text=\"Frequency\", font=dict(size=20, color=INK)),\n        ),\n        angularaxis=dict(\n            tickfont=dict(size=22, color=INK), direction=\"clockwise\", rotation=90, gridcolor=GRID, linecolor=INK_SOFT\n        ),\n    ),\n    legend=dict(\n        font=dict(size=18, color=INK_SOFT), x=0.85, y=0.95, bgcolor=ELEVATED_BG, bordercolor=INK_SOFT, borderwidth=1\n    ),\n    margin=dict(l=100, r=200, t=120, b=100),\n)\n\n# Save as PNG (4800 x 2700 px) and interactive HTML\nfig.write_image(f\"plot-{THEME}.png\", width=1600, height=900, scale=3)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}