{"spec_id":"range-interval","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\nrange-interval: Range Interval Chart\nLibrary: pygal 3.1.0 | Python 3.13.13\nQuality: 90/100 | Updated: 2026-05-18\n\"\"\"\n\nimport os\nimport sys\n\n\n# Avoid importing local pygal.py file; ensure we get the installed pygal package\nscript_dir = os.path.dirname(os.path.abspath(__file__))\nif script_dir in sys.path:\n    sys.path.remove(script_dir)\n\nimport pygal\nfrom pygal.style import Style\n\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\nIMPRINT = (\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\")\n\n# Data: Monthly temperature ranges (daily high/low averages)\nmonths = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"]\ntemp_min = [-2, 0, 4, 8, 13, 17, 19, 18, 14, 9, 4, 0]\ntemp_max = [6, 8, 12, 16, 21, 25, 28, 27, 22, 16, 10, 7]\n\n# Calculate the range for stacked bar visualization\ntemp_range = [high - low for low, high in zip(temp_min, temp_max, strict=True)]\n\n# Custom style with theme-adaptive tokens\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,\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)\n\n# Create stacked bar chart (first series base, second series visible range)\nchart = pygal.StackedBar(\n    width=4800,\n    height=2700,\n    style=custom_style,\n    title=\"range-interval · python · pygal · anyplot.ai\",\n    x_title=\"Month\",\n    y_title=\"Temperature (°C)\",\n    show_legend=True,\n    legend_at_bottom=True,\n    show_y_guides=True,\n    show_x_guides=False,\n    print_values=False,\n    spacing=40,\n    margin=80,\n    margin_bottom=150,\n    margin_left=150,\n)\n\n# Set x-axis labels\nchart.x_labels = months\n\n# Add invisible base (from 0 to min_value)\nchart.add(\"\", temp_min, show_dots=False)\n\n# Add visible range bars (from min to max) in brand color\nchart.add(\"Temperature Range (°C)\", temp_range, show_dots=False)\n\n# Render to PNG and HTML\nchart.render_to_png(f\"plot-{THEME}.png\")\nwith open(f\"plot-{THEME}.html\", \"wb\") as f:\n    f.write(chart.render())\n"}