{"spec_id":"qrcode-basic","library":"letsplot","language":"python","code":"\"\"\" anyplot.ai\nqrcode-basic: Basic QR Code Generator\nLibrary: letsplot 4.10.1 | Python 3.13.14\nQuality: 86/100 | Updated: 2026-06-24\n\"\"\"\n\nimport os\n\nimport pandas as pd\nimport qrcode\nfrom lets_plot import (\n    LetsPlot,\n    aes,\n    coord_fixed,\n    element_rect,\n    element_text,\n    geom_raster,\n    ggplot,\n    ggsave,\n    ggsize,\n    labs,\n    scale_fill_identity,\n    theme,\n    theme_void,\n)\n\n\nLetsPlot.setup_html()\n\n# Theme-adaptive chrome tokens (Imprint palette)\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\n# Generate QR code data\ncontent = \"https://pyplots.ai\"\nqr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_M, box_size=1, border=4)\nqr.add_data(content)\nqr.make(fit=True)\n\n# Convert QR matrix to dataframe — fill column used directly by scale_fill_identity\nmatrix = qr.get_matrix()\nsize = len(matrix)\nrows = []\nfor y, row in enumerate(matrix):\n    for x, cell in enumerate(row):\n        rows.append({\"x\": x, \"y\": size - 1 - y, \"fill\": INK if cell else PAGE_BG})\ndf = pd.DataFrame(rows)\n\n# Title length: 46 chars — shorter than 67-char baseline, use default 16px\ntitle = \"qrcode-basic · python · letsplot · anyplot.ai\"\n\n# Plot — square canvas: ggsize(600, 600) × scale=4 → 2400×2400 px (hard rule)\nplot = (\n    ggplot(df, aes(x=\"x\", y=\"y\", fill=\"fill\"))\n    + geom_raster()\n    + scale_fill_identity()\n    + coord_fixed()\n    + labs(\n        title=title,\n        subtitle=f\"Encoded: {content}  |  Error Correction: M (15%)\",\n        caption=f\"Version {qr.version}  ·  {size}×{size} modules  ·  ECC Level M (15%)\",\n    )\n    + ggsize(600, 600)\n    + theme_void()\n    + theme(\n        plot_title=element_text(size=16, hjust=0.5, face=\"bold\", color=INK),\n        plot_subtitle=element_text(size=10, hjust=0.5, color=INK_SOFT),\n        plot_caption=element_text(size=8, hjust=0.5, color=INK_MUTED),\n        plot_background=element_rect(fill=PAGE_BG, color=\"#009E73\", size=3),\n        panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n    )\n)\n\n# Save — square 2400×2400 px (PNG + HTML for interactive library)\nggsave(plot, f\"plot-{THEME}.png\", path=\".\", scale=4)\nggsave(plot, f\"plot-{THEME}.html\", path=\".\")\n"}