{"spec_id":"funnel-basic","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nfunnel-basic: Basic Funnel Chart\nLibrary: plotly 7.1.0 | Python 3.14.9\nQuality: 82/100 | Updated: 2026-11-02\n\"\"\"\n\nimport os\n\nimport pandas as pd\nimport plotly.graph_objects as go\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\"\nGRID = \"rgba(26,26,23,0.10)\" if THEME == \"light\" else \"rgba(240,239,232,0.10)\"\n\n# Imprint palette: all eight positions, one per stage in order\nIMPRINT_PALETTE = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\"]\n\n# Columns: set these to your table's column names\nSTAGE = \"Stage\"  # role: stage\nVALUE = \"Count\"  # role: value\n\n# Data: replace this block with your own table, for example df = pd.read_csv(\"funnel.csv\")\ndf = pd.DataFrame(\n    {STAGE: [\"Awareness\", \"Interest\", \"Consideration\", \"Intent\", \"Purchase\"], VALUE: [1000, 600, 400, 200, 100]}\n)\n\n# Plot: reads only df and the constants above\nfig = go.Figure(\n    go.Funnel(\n        y=df[STAGE],\n        x=df[VALUE],\n        textposition=\"inside\",\n        textinfo=\"value+percent initial\",\n        textfont={\"size\": 12, \"color\": \"#FAF8F1\"},\n        marker={\"color\": IMPRINT_PALETTE[: len(df)], \"line\": {\"width\": 1, \"color\": PAGE_BG}},\n        connector={\"line\": {\"color\": INK_SOFT, \"width\": 1, \"dash\": \"dot\"}},\n    )\n)\n\n# Style\nfig.update_layout(\n    title={\n        \"text\": \"funnel-basic · python · plotly · anyplot.ai\",\n        \"font\": {\"size\": 16, \"color\": INK},\n        \"x\": 0.5,\n        \"xanchor\": \"center\",\n    },\n    yaxis={\n        \"title\": {\"text\": STAGE, \"font\": {\"size\": 12, \"color\": INK}},\n        \"tickfont\": {\"size\": 10, \"color\": INK_SOFT},\n        \"gridcolor\": GRID,\n        \"linecolor\": INK_SOFT,\n        \"zerolinecolor\": INK_SOFT,\n    },\n    xaxis={\n        \"title\": {\"text\": VALUE, \"font\": {\"size\": 12, \"color\": INK}},\n        \"tickfont\": {\"size\": 10, \"color\": INK_SOFT},\n        \"gridcolor\": GRID,\n        \"linecolor\": INK_SOFT,\n        \"zerolinecolor\": INK_SOFT,\n    },\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font={\"color\": INK},\n    autosize=False,\n    margin={\"l\": 100, \"r\": 40, \"t\": 60, \"b\": 50},\n    showlegend=False,\n)\n\n# Save\nfig.write_image(f\"plot-{THEME}.png\", width=800, height=450, scale=4)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}