{"spec_id":"polar-basic","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\npolar-basic: Basic Polar Chart\nLibrary: pygal 3.1.3 | Python 3.13.14\nQuality: 88/100 | Updated: 2026-07-24\n\"\"\"\n\nimport importlib\nimport os\nimport sys\n\nimport numpy as np\n\n\n# Remove script dir so 'pygal' resolves to the installed package, not this file\n_d = os.path.abspath(os.path.dirname(__file__))\nsys.path = [p for p in sys.path if os.path.abspath(p) != _d]\nos.chdir(_d)\n\npygal = importlib.import_module(\"pygal\")\nStyle = importlib.import_module(\"pygal.style\").Style\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\n# Imprint palette — first series always brand green\nIMPRINT_PALETTE = (\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\")\n\n# Data — hourly temperature readings over a 24-hour cycle\nnp.random.seed(42)\nhours = np.arange(24)\nbase_temp = 15 + 8 * np.sin((hours - 6) * np.pi / 12)  # peak at noon\ntemperature = base_temp + np.random.randn(24) * 1.5\npeak_idx = int(np.argmax(temperature))\n\n# Angular labels at standard cardinal intervals (00:00, 06:00, 12:00, 18:00),\n# plus a callout on the peak hour to emphasize the diurnal cycle's high point\n# — dense per-hour labels would crowd a circular axis, so every other point\n# stays unlabeled.\ncardinal_hours = {0, 6, 12, 18}\n\n\ndef _hour_label(h):\n    if h == peak_idx:\n        return f\"{h:02d}:00 (peak)\"\n    if h in cardinal_hours:\n        return f\"{h:02d}:00\"\n    return \"\"\n\n\nhour_labels = [_hour_label(h) for h in hours]\n\n# Style — canonical pygal sizing for the 2400x2400 canvas (native-pixel family)\ncustom_style = Style(\n    background=PAGE_BG,\n    plot_background=PAGE_BG,\n    foreground=INK,\n    foreground_strong=INK,\n    foreground_subtle=INK_MUTED,\n    colors=IMPRINT_PALETTE,\n    title_font_size=66,\n    label_font_size=56,\n    major_label_font_size=44,\n    legend_font_size=44,\n    value_font_size=36,\n    stroke_width=4,\n)\n\n# Plot — radar chart for cyclical polar data\nchart = pygal.Radar(\n    style=custom_style,\n    width=2400,\n    height=2400,\n    title=\"Hourly Temperature (°C) · polar-basic · python · pygal · anyplot.ai\",\n    show_legend=False,\n    fill=True,\n    dots_size=9,\n    show_y_guides=True,\n    inner_radius=0.1,\n    margin_top=140,\n)\n\nchart.x_labels = hour_labels\nchart.add(\"Temperature (°C)\", [float(t) for t in temperature])\n\n# Save\nchart.render_to_png(f\"plot-{THEME}.png\")\nwith open(f\"plot-{THEME}.html\", \"wb\") as f:\n    f.write(chart.render())\n"}