{"spec_id":"qrcode-basic","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nqrcode-basic: Basic QR Code Generator\nLibrary: plotly 6.8.0 | Python 3.13.14\nQuality: 88/100 | Updated: 2026-06-24\n\"\"\"\n\nimport os\nimport sys\n\n\n# Remove this script's directory from sys.path so `import plotly` finds the\n# installed package rather than this file itself (plotly.py would shadow it).\n_here = os.path.dirname(os.path.abspath(__file__))\nsys.path = [p for p in sys.path if os.path.abspath(p) != _here]\n\nimport numpy as np\nimport plotly.graph_objects as go\nimport qrcode\n\n\n# Theme-adaptive chrome tokens (Imprint palette)\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# Imprint palette position 1 — brand green accent for chrome\nACCENT = \"#009E73\"\n\n# QR code modules: ink on page background for maximum contrast + theme consistency\nMODULE_DARK = INK\nMODULE_LIGHT = PAGE_BG\n\n# Data — generate QR code for pyplots.ai\ncontent = \"https://pyplots.ai\"\nqr = qrcode.QRCode(version=None, error_correction=qrcode.constants.ERROR_CORRECT_M, box_size=1, border=4)\nqr.add_data(content)\nqr.make(fit=True)\nqr_matrix = np.array(qr.get_matrix(), dtype=int)\nn_modules = qr_matrix.shape[0]\n\n# Plot — render as heatmap with theme-adaptive colorscale\nfig = go.Figure(\n    data=go.Heatmap(\n        z=qr_matrix,\n        colorscale=[[0, MODULE_LIGHT], [1, MODULE_DARK]],\n        showscale=False,\n        xgap=0.4,\n        ygap=0.4,\n        hovertemplate=\"Module: (%{x}, %{y})<extra></extra>\",\n    )\n)\n\nfig.update_layout(\n    autosize=False,\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font={\"color\": INK},\n    title={\n        \"text\": \"qrcode-basic · python · plotly · anyplot.ai\",\n        \"font\": {\"size\": 16, \"color\": INK, \"family\": \"Arial Black, sans-serif\"},\n        \"x\": 0.5,\n        \"xanchor\": \"center\",\n        \"y\": 0.98,\n    },\n    xaxis={\n        \"showticklabels\": False,\n        \"showgrid\": False,\n        \"zeroline\": False,\n        \"scaleanchor\": \"y\",\n        \"scaleratio\": 1,\n        \"constrain\": \"domain\",\n        \"showline\": False,\n        \"range\": [-0.5, n_modules - 0.5],\n    },\n    yaxis={\n        \"showticklabels\": False,\n        \"showgrid\": False,\n        \"zeroline\": False,\n        \"autorange\": \"reversed\",\n        \"constrain\": \"domain\",\n        \"showline\": False,\n        \"range\": [-0.5, n_modules - 0.5],\n    },\n    margin={\"l\": 40, \"r\": 40, \"t\": 80, \"b\": 130},\n)\n\n# Accent border framing the QR code area\nfig.add_shape(\n    type=\"rect\",\n    xref=\"paper\",\n    yref=\"paper\",\n    x0=-0.01,\n    y0=-0.01,\n    x1=1.01,\n    y1=1.01,\n    line={\"color\": ACCENT, \"width\": 1.5},\n    fillcolor=\"rgba(0,0,0,0)\",\n    opacity=0.7,\n)\n\n# Dotted divider between QR code and annotation area\nfig.add_shape(\n    type=\"line\",\n    xref=\"paper\",\n    yref=\"paper\",\n    x0=0.25,\n    y0=-0.06,\n    x1=0.75,\n    y1=-0.06,\n    line={\"color\": ACCENT, \"width\": 1.5, \"dash\": \"dot\"},\n    opacity=0.5,\n)\n\n# Encoded URL — prominent, just below the divider\nfig.add_annotation(\n    text=f\"<b>{content}</b>\",\n    xref=\"paper\",\n    yref=\"paper\",\n    x=0.5,\n    y=-0.14,\n    showarrow=False,\n    font={\"size\": 12, \"color\": ACCENT, \"family\": \"Arial, sans-serif\"},\n    xanchor=\"center\",\n    yanchor=\"top\",\n)\n\n# QR code metadata — version, error correction, module count\nfig.add_annotation(\n    text=f\"Error Correction: M (15%)  ·  Version {qr.version}  ·  {n_modules}×{n_modules} modules\",\n    xref=\"paper\",\n    yref=\"paper\",\n    x=0.5,\n    y=-0.27,\n    showarrow=False,\n    font={\"size\": 12, \"color\": INK_SOFT, \"family\": \"Arial, sans-serif\"},\n    xanchor=\"center\",\n    yanchor=\"top\",\n)\n\n# Save — square canvas: 600×600 logical → 2400×2400 px at scale=4\nfig.write_image(f\"plot-{THEME}.png\", width=600, height=600, scale=4)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}