{"spec_id":"qrcode-basic","library":"plotnine","language":"python","code":"\"\"\" anyplot.ai\nqrcode-basic: Basic QR Code Generator\nLibrary: plotnine 0.15.7 | Python 3.13.14\nQuality: 88/100 | Created: 2026-06-24\n\"\"\"\n\nimport os\nimport sys\n\n\n_script_dir = os.path.dirname(os.path.abspath(__file__))\nsys.path = [p for p in sys.path if p and os.path.abspath(p) != _script_dir]\n\nimport pandas as pd\nimport qrcode\nimport qrcode.constants\nfrom plotnine import (\n    aes,\n    coord_fixed,\n    element_rect,\n    element_text,\n    geom_tile,\n    ggplot,\n    labs,\n    scale_fill_manual,\n    theme,\n    theme_void,\n)\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_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# QR module colors — dark on light bg / light on dark bg for scannability\nMODULE_ON = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nMODULE_OFF = PAGE_BG  # quiet zone matches page background\n\n# Data — encode anyplot.ai URL with error correction level M (15%)\nURL = \"https://anyplot.ai\"\nqr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_M, box_size=1, border=4)\nqr.add_data(URL)\nqr.make(fit=True)\n\nmatrix = qr.get_matrix()\nn = len(matrix)\n\nrows = []\nfor r, row in enumerate(matrix):\n    for c, val in enumerate(row):\n        rows.append({\"x\": c, \"y\": n - 1 - r, \"module\": \"on\" if val else \"off\"})\ndf = pd.DataFrame(rows)\n\n# Plot\ntitle = \"qrcode-basic · python · plotnine · anyplot.ai\"\n\nplot = (\n    ggplot(df, aes(x=\"x\", y=\"y\", fill=\"module\"))\n    + geom_tile(width=1.02, height=1.02)\n    + scale_fill_manual(values={\"on\": MODULE_ON, \"off\": MODULE_OFF})\n    + coord_fixed()\n    + labs(title=title, subtitle=URL)\n    + theme_void()\n    + theme(\n        figure_size=(6, 6),\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_background=element_rect(fill=PAGE_BG),\n        plot_title=element_text(color=INK, size=12, ha=\"center\"),\n        plot_subtitle=element_text(color=INK_SOFT, size=9, ha=\"center\"),\n        legend_position=\"none\",\n    )\n)\n\n# Save\nplot.save(f\"plot-{THEME}.png\", dpi=400, width=6, height=6, units=\"in\")\n"}