{"spec_id":"rose-basic","library":"letsplot","language":"python","code":"\"\"\" anyplot.ai\nrose-basic: Basic Rose Chart\nLibrary: letsplot 4.11.0 | Python 3.13.14\nQuality: 86/100 | Updated: 2026-07-25\n\"\"\"\n\nimport os\n\nimport pandas as pd\nfrom lets_plot import (\n    LetsPlot,\n    aes,\n    coord_polar,\n    element_blank,\n    element_line,\n    element_rect,\n    element_text,\n    geom_bar,\n    ggplot,\n    ggsize,\n    labs,\n    theme,\n    theme_minimal,\n)\nfrom lets_plot.export import ggsave\nfrom PIL import Image\n\n\nLetsPlot.setup_html()\n\n# Theme-adaptive chrome (Imprint)\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nPAGE_BG_RGB = (250, 248, 241) if THEME == \"light\" else (26, 26, 23)\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nBRAND = \"#009E73\"  # Imprint palette position 1 — always first/only series\n\n# Data - Monthly rainfall (mm) showing seasonal patterns\nmonths = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"]\nrainfall = [78, 65, 82, 95, 120, 145, 168, 155, 130, 105, 85, 70]\n\ndf = pd.DataFrame({\"month\": months, \"rainfall\": rainfall})\n# Maintain natural month ordering\ndf[\"month\"] = pd.Categorical(df[\"month\"], categories=months, ordered=True)\n\n# Plot - Rose chart using polar coordinates; single metric uses one Imprint hue\nplot = (\n    ggplot(df, aes(x=\"month\", y=\"rainfall\"))\n    + geom_bar(stat=\"identity\", width=0.9, fill=BRAND, alpha=0.9)\n    + coord_polar()\n    + labs(title=\"Monthly Rainfall Distribution · rose-basic · letsplot · anyplot.ai\", x=\"\", y=\"Rainfall (mm)\")\n    + theme_minimal()\n    + theme(\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_background=element_rect(fill=PAGE_BG),\n        panel_border=element_blank(),\n        panel_grid_major=element_line(color=INK_SOFT, size=0.3),\n        panel_grid_major_x=element_blank(),  # drop angular spokes, keep radial rings\n        panel_grid_minor=element_blank(),  # minor gridlines also draw angular spokes in polar coords\n        # Title fontsize scaled for the narrower 600px-wide square canvas (2400px final)\n        plot_title=element_text(size=12, face=\"bold\", color=INK),\n        axis_title_y=element_text(size=12, color=INK),\n        axis_text_x=element_text(size=10, color=INK_SOFT),\n        axis_text_y=element_text(size=10, color=INK_SOFT),\n    )\n    + ggsize(600, 600)\n)\n\n# Save\nggsave(plot, f\"plot-{THEME}.png\", path=\".\", scale=4)\n\n# coord_polar()'s layout pass leaves a transparent margin around the plot when a\n# title is present; flatten it onto the theme background so PNG edges are opaque.\nimg = Image.open(f\"plot-{THEME}.png\").convert(\"RGBA\")\nbg = Image.new(\"RGBA\", img.size, (*PAGE_BG_RGB, 255))\nImage.alpha_composite(bg, img).convert(\"RGB\").save(f\"plot-{THEME}.png\")\n\nggsave(plot, f\"plot-{THEME}.html\", path=\".\")\n"}