[{"data":1,"prerenderedAt":730},["ShallowReactive",2],{"content-query-blDdPrAMGz":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"heading":10,"prompt":11,"tags":15,"files":17,"nav":6,"presets":18,"gallery":36,"body":38,"_type":723,"_id":724,"_source":725,"_file":726,"_stem":727,"_extension":728,"sitemap":729},"/tools/ai-sankey-diagram","tools",false,"","Sankey Diagram Generator for Excel & CSV","Create Sankey diagrams online from Excel and CSV data. Visualize flows between stages, sources, and destinations with AI.","Sankey Diagram Generator",{"prefix":12,"label":13,"placeholder":14},"Create a Sankey diagram","Describe the flow diagram you want","e.g. show energy flow from sources to end uses",[16],"charts",true,[19,25,31],{"label":20,"prompt":21,"dataset_url":22,"dataset_title":23,"dataset_citation":24},"US energy consumption by sector","create a Sankey diagram showing energy flow from source types (coal, gas, renewables, nuclear, petroleum) to end-use sectors (residential, commercial, industrial, transportation). Use the most recent year available.","https://ourworldindata.org/grapher/energy-consumption-by-source-and-region.csv","Energy consumption by source","Our World in Data",{"label":26,"prompt":27,"dataset_url":28,"dataset_title":29,"dataset_citation":30},"COVID deaths by age and sex","create a Sankey diagram showing flow from age groups to sex categories, sized by number of COVID-19 deaths","https://data.cdc.gov/api/views/9bhg-hcku/rows.csv?accessType=DOWNLOAD","Provisional COVID-19 Deaths by Sex and Age","CDC",{"label":32,"prompt":33,"dataset_url":34,"dataset_title":35,"dataset_citation":30},"Drug overdose deaths by drug type","create a Sankey diagram showing overdose deaths flowing from drug type (opioids, stimulants, etc.) to demographic groups (age group or sex)","https://data.cdc.gov/api/views/95ax-ymtc/rows.csv?accessType=DOWNLOAD","Drug Overdose Death Rates, by Drug Type, Sex, Age, Race, and Hispanic Origin",[37],"/img/tools/sankey-diagram.png",{"type":39,"children":40,"toc":712},"root",[41,50,64,76,95,101,142,156,162,167,252,257,263,365,370,376,501,507,571,577,620,626,636,653,670,694],{"type":42,"tag":43,"props":44,"children":46},"element","h2",{"id":45},"what-is-a-sankey-diagram",[47],{"type":48,"value":49},"text","What Is a Sankey Diagram?",{"type":42,"tag":51,"props":52,"children":53},"p",{},[54,56,62],{"type":48,"value":55},"A ",{"type":42,"tag":57,"props":58,"children":59},"strong",{},[60],{"type":48,"value":61},"Sankey diagram",{"type":48,"value":63}," is a flow visualization where the width of each arrow or band is proportional to the quantity it represents. Named after Irish engineer Matthew Henry Phineas Riall Sankey, who used the format in 1898 to show steam engine energy efficiency, Sankey diagrams are today used everywhere from energy audits to budget analysis to user journey mapping.",{"type":42,"tag":51,"props":65,"children":66},{},[67,69,74],{"type":48,"value":68},"Unlike a pie chart or bar chart, a Sankey diagram shows ",{"type":42,"tag":57,"props":70,"children":71},{},[72],{"type":48,"value":73},"where things come from and where they go",{"type":48,"value":75}," — making it ideal for tracing flows through a system. For example: how electricity generated from coal, gas, and renewables is ultimately consumed by households, factories, and transportation; or how a government budget flows from departments down to specific programs.",{"type":42,"tag":51,"props":77,"children":78},{},[79,81,86,88,93],{"type":48,"value":80},"The key features are ",{"type":42,"tag":57,"props":82,"children":83},{},[84],{"type":48,"value":85},"nodes",{"type":48,"value":87}," (the boxes or columns representing categories) and ",{"type":42,"tag":57,"props":89,"children":90},{},[91],{"type":48,"value":92},"links",{"type":48,"value":94}," (the bands connecting them, sized by flow volume). Multiple layers of nodes can be added to show multi-step flows.",{"type":42,"tag":43,"props":96,"children":98},{"id":97},"how-it-works",[99],{"type":48,"value":100},"How It Works",{"type":42,"tag":102,"props":103,"children":104},"ol",{},[105,116,132],{"type":42,"tag":106,"props":107,"children":108},"li",{},[109,114],{"type":42,"tag":57,"props":110,"children":111},{},[112],{"type":48,"value":113},"Upload your data",{"type":48,"value":115}," — CSV or Excel with at least three columns: a source column, a target column, and a numeric value column",{"type":42,"tag":106,"props":117,"children":118},{},[119,124,126],{"type":42,"tag":57,"props":120,"children":121},{},[122],{"type":48,"value":123},"Describe your diagram",{"type":48,"value":125}," — e.g. ",{"type":42,"tag":127,"props":128,"children":129},"em",{},[130],{"type":48,"value":131},"\"Sankey diagram from the 'from' column to the 'to' column, sized by value\"",{"type":42,"tag":106,"props":133,"children":134},{},[135,140],{"type":42,"tag":57,"props":136,"children":137},{},[138],{"type":48,"value":139},"Get an interactive chart",{"type":48,"value":141}," — hover links to see exact flow values; ask the AI to recolor, reorder nodes, or filter to specific paths",{"type":42,"tag":51,"props":143,"children":144},{},[145,147,154],{"type":48,"value":146},"The AI generates Python code using ",{"type":42,"tag":148,"props":149,"children":151},"a",{"href":150},"https://plotly.com/python/sankey-diagram/",[152],{"type":48,"value":153},"Plotly",{"type":48,"value":155}," which produces an interactive Sankey with tooltips, drag-to-rearrange nodes, and exportable output.",{"type":42,"tag":43,"props":157,"children":159},{"id":158},"data-format",[160],{"type":48,"value":161},"Data Format",{"type":42,"tag":51,"props":163,"children":164},{},[165],{"type":48,"value":166},"Your data should have one row per flow, with columns like:",{"type":42,"tag":168,"props":169,"children":170},"table",{},[171,195],{"type":42,"tag":172,"props":173,"children":174},"thead",{},[175],{"type":42,"tag":176,"props":177,"children":178},"tr",{},[179,185,190],{"type":42,"tag":180,"props":181,"children":182},"th",{},[183],{"type":48,"value":184},"source",{"type":42,"tag":180,"props":186,"children":187},{},[188],{"type":48,"value":189},"target",{"type":42,"tag":180,"props":191,"children":192},{},[193],{"type":48,"value":194},"value",{"type":42,"tag":196,"props":197,"children":198},"tbody",{},[199,218,235],{"type":42,"tag":176,"props":200,"children":201},{},[202,208,213],{"type":42,"tag":203,"props":204,"children":205},"td",{},[206],{"type":48,"value":207},"Coal",{"type":42,"tag":203,"props":209,"children":210},{},[211],{"type":48,"value":212},"Industry",{"type":42,"tag":203,"props":214,"children":215},{},[216],{"type":48,"value":217},"14",{"type":42,"tag":176,"props":219,"children":220},{},[221,225,230],{"type":42,"tag":203,"props":222,"children":223},{},[224],{"type":48,"value":207},{"type":42,"tag":203,"props":226,"children":227},{},[228],{"type":48,"value":229},"Residential",{"type":42,"tag":203,"props":231,"children":232},{},[233],{"type":48,"value":234},"10",{"type":42,"tag":176,"props":236,"children":237},{},[238,243,247],{"type":42,"tag":203,"props":239,"children":240},{},[241],{"type":48,"value":242},"Wind",{"type":42,"tag":203,"props":244,"children":245},{},[246],{"type":48,"value":229},{"type":42,"tag":203,"props":248,"children":249},{},[250],{"type":48,"value":251},"4",{"type":42,"tag":51,"props":253,"children":254},{},[255],{"type":48,"value":256},"Column names don't have to match exactly — just tell the AI which columns to use. The AI can also aggregate grouped data (e.g. a pivot table) into the source-target-value format automatically.",{"type":42,"tag":43,"props":258,"children":260},{"id":259},"interpreting-the-results",[261],{"type":48,"value":262},"Interpreting the Results",{"type":42,"tag":168,"props":264,"children":265},{},[266,282],{"type":42,"tag":172,"props":267,"children":268},{},[269],{"type":42,"tag":176,"props":270,"children":271},{},[272,277],{"type":42,"tag":180,"props":273,"children":274},{},[275],{"type":48,"value":276},"Element",{"type":42,"tag":180,"props":278,"children":279},{},[280],{"type":48,"value":281},"What it means",{"type":42,"tag":196,"props":283,"children":284},{},[285,301,317,333,349],{"type":42,"tag":176,"props":286,"children":287},{},[288,296],{"type":42,"tag":203,"props":289,"children":290},{},[291],{"type":42,"tag":57,"props":292,"children":293},{},[294],{"type":48,"value":295},"Node width",{"type":42,"tag":203,"props":297,"children":298},{},[299],{"type":48,"value":300},"Total flow passing through that category",{"type":42,"tag":176,"props":302,"children":303},{},[304,312],{"type":42,"tag":203,"props":305,"children":306},{},[307],{"type":42,"tag":57,"props":308,"children":309},{},[310],{"type":48,"value":311},"Link width",{"type":42,"tag":203,"props":313,"children":314},{},[315],{"type":48,"value":316},"Volume of flow between two specific nodes",{"type":42,"tag":176,"props":318,"children":319},{},[320,328],{"type":42,"tag":203,"props":321,"children":322},{},[323],{"type":42,"tag":57,"props":324,"children":325},{},[326],{"type":48,"value":327},"Link color",{"type":42,"tag":203,"props":329,"children":330},{},[331],{"type":48,"value":332},"Usually inherits from the source node (customizable)",{"type":42,"tag":176,"props":334,"children":335},{},[336,344],{"type":42,"tag":203,"props":337,"children":338},{},[339],{"type":42,"tag":57,"props":340,"children":341},{},[342],{"type":48,"value":343},"Node order",{"type":42,"tag":203,"props":345,"children":346},{},[347],{"type":48,"value":348},"Left-to-right represents stages in the process",{"type":42,"tag":176,"props":350,"children":351},{},[352,360],{"type":42,"tag":203,"props":353,"children":354},{},[355],{"type":42,"tag":57,"props":356,"children":357},{},[358],{"type":48,"value":359},"Hover tooltip",{"type":42,"tag":203,"props":361,"children":362},{},[363],{"type":48,"value":364},"Shows exact value and percentage for each link",{"type":42,"tag":51,"props":366,"children":367},{},[368],{"type":48,"value":369},"A wide link means a large proportion of the source flows to that destination. Thin links are minor pathways. If a node has many thin outgoing links, the flow is highly distributed.",{"type":42,"tag":43,"props":371,"children":373},{"id":372},"example-prompts",[374],{"type":48,"value":375},"Example Prompts",{"type":42,"tag":168,"props":377,"children":378},{},[379,395],{"type":42,"tag":172,"props":380,"children":381},{},[382],{"type":42,"tag":176,"props":383,"children":384},{},[385,390],{"type":42,"tag":180,"props":386,"children":387},{},[388],{"type":48,"value":389},"Scenario",{"type":42,"tag":180,"props":391,"children":392},{},[393],{"type":48,"value":394},"What to type",{"type":42,"tag":196,"props":396,"children":397},{},[398,416,433,450,467,484],{"type":42,"tag":176,"props":399,"children":400},{},[401,406],{"type":42,"tag":203,"props":402,"children":403},{},[404],{"type":48,"value":405},"Basic flow",{"type":42,"tag":203,"props":407,"children":408},{},[409],{"type":42,"tag":410,"props":411,"children":413},"code",{"className":412},[],[414],{"type":48,"value":415},"Sankey diagram from 'source' to 'target' sized by 'amount'",{"type":42,"tag":176,"props":417,"children":418},{},[419,424],{"type":42,"tag":203,"props":420,"children":421},{},[422],{"type":48,"value":423},"Multi-layer flow",{"type":42,"tag":203,"props":425,"children":426},{},[427],{"type":42,"tag":410,"props":428,"children":430},{"className":429},[],[431],{"type":48,"value":432},"three-level Sankey: department → program → budget item",{"type":42,"tag":176,"props":434,"children":435},{},[436,441],{"type":42,"tag":203,"props":437,"children":438},{},[439],{"type":48,"value":440},"Filter to top flows",{"type":42,"tag":203,"props":442,"children":443},{},[444],{"type":42,"tag":410,"props":445,"children":447},{"className":446},[],[448],{"type":48,"value":449},"Sankey showing only flows larger than 1000 units",{"type":42,"tag":176,"props":451,"children":452},{},[453,458],{"type":42,"tag":203,"props":454,"children":455},{},[456],{"type":48,"value":457},"Custom colors",{"type":42,"tag":203,"props":459,"children":460},{},[461],{"type":42,"tag":410,"props":462,"children":464},{"className":463},[],[465],{"type":48,"value":466},"Sankey with green for renewable sources and gray for fossil fuels",{"type":42,"tag":176,"props":468,"children":469},{},[470,475],{"type":42,"tag":203,"props":471,"children":472},{},[473],{"type":48,"value":474},"Percentage labels",{"type":42,"tag":203,"props":476,"children":477},{},[478],{"type":42,"tag":410,"props":479,"children":481},{"className":480},[],[482],{"type":48,"value":483},"add percentage labels to each link",{"type":42,"tag":176,"props":485,"children":486},{},[487,492],{"type":42,"tag":203,"props":488,"children":489},{},[490],{"type":48,"value":491},"Aggregate first",{"type":42,"tag":203,"props":493,"children":494},{},[495],{"type":42,"tag":410,"props":496,"children":498},{"className":497},[],[499],{"type":48,"value":500},"group by region and category, then draw a Sankey",{"type":42,"tag":43,"props":502,"children":504},{"id":503},"common-use-cases",[505],{"type":48,"value":506},"Common Use Cases",{"type":42,"tag":508,"props":509,"children":510},"ul",{},[511,521,531,541,551,561],{"type":42,"tag":106,"props":512,"children":513},{},[514,519],{"type":42,"tag":57,"props":515,"children":516},{},[517],{"type":48,"value":518},"Energy systems",{"type":48,"value":520}," — sources (coal, gas, solar) → conversion → end uses (heating, transport, industry)",{"type":42,"tag":106,"props":522,"children":523},{},[524,529],{"type":42,"tag":57,"props":525,"children":526},{},[527],{"type":48,"value":528},"Budget allocation",{"type":48,"value":530}," — ministry → department → program → expense type",{"type":42,"tag":106,"props":532,"children":533},{},[534,539],{"type":42,"tag":57,"props":535,"children":536},{},[537],{"type":48,"value":538},"Supply chains",{"type":48,"value":540}," — raw materials → manufacturing → distribution → retail",{"type":42,"tag":106,"props":542,"children":543},{},[544,549],{"type":42,"tag":57,"props":545,"children":546},{},[547],{"type":48,"value":548},"User journeys",{"type":48,"value":550}," — landing page → feature → conversion or drop-off",{"type":42,"tag":106,"props":552,"children":553},{},[554,559],{"type":42,"tag":57,"props":555,"children":556},{},[557],{"type":48,"value":558},"Migration",{"type":48,"value":560}," — origin countries → destination countries, sized by number of people",{"type":42,"tag":106,"props":562,"children":563},{},[564,569],{"type":42,"tag":57,"props":565,"children":566},{},[567],{"type":48,"value":568},"Cause of death",{"type":48,"value":570}," — age group → cause → sex",{"type":42,"tag":43,"props":572,"children":574},{"id":573},"assumptions-to-check",[575],{"type":48,"value":576},"Assumptions to Check",{"type":42,"tag":508,"props":578,"children":579},{},[580,590,600,610],{"type":42,"tag":106,"props":581,"children":582},{},[583,588],{"type":42,"tag":57,"props":584,"children":585},{},[586],{"type":48,"value":587},"Flows should balance",{"type":48,"value":589}," — for each intermediate node, inflow should equal outflow. If your data represents a one-step flow (just sources and sinks), this isn't an issue.",{"type":42,"tag":106,"props":591,"children":592},{},[593,598],{"type":42,"tag":57,"props":594,"children":595},{},[596],{"type":48,"value":597},"No negative values",{"type":48,"value":599}," — Sankey link widths must be positive. Negative flows (e.g. returns, refunds) require special handling — ask the AI to reverse the direction of those links.",{"type":42,"tag":106,"props":601,"children":602},{},[603,608],{"type":42,"tag":57,"props":604,"children":605},{},[606],{"type":48,"value":607},"Column types",{"type":48,"value":609}," — the value column must be numeric. Source and target must be strings or categories. Ask the AI to clean up the data types if needed.",{"type":42,"tag":106,"props":611,"children":612},{},[613,618],{"type":42,"tag":57,"props":614,"children":615},{},[616],{"type":48,"value":617},"Cycles",{"type":48,"value":619}," — Plotly's Sankey does not support circular flows (e.g. A → B → A). If your data has cycles, ask the AI to break them by adding a time subscript (e.g. A_t1 → B → A_t2).",{"type":42,"tag":43,"props":621,"children":623},{"id":622},"frequently-asked-questions",[624],{"type":48,"value":625},"Frequently Asked Questions",{"type":42,"tag":51,"props":627,"children":628},{},[629,634],{"type":42,"tag":57,"props":630,"children":631},{},[632],{"type":48,"value":633},"What's the difference between a Sankey diagram and an alluvial diagram?",{"type":48,"value":635},"\nThey look similar but differ in purpose. A Sankey diagram shows the magnitude of flows through a system (widths encode quantities). An alluvial diagram shows how categorical groupings change over time or across dimensions — widths encode counts within each group. Ask for an \"alluvial diagram\" if you want to track how observations move between categories (e.g. survey responses over multiple rounds).",{"type":42,"tag":51,"props":637,"children":638},{},[639,644,646,651],{"type":42,"tag":57,"props":640,"children":641},{},[642],{"type":48,"value":643},"My data is wide-format (a matrix of flows). Can I still use it?",{"type":48,"value":645},"\nYes — upload your pivot/matrix and tell the AI: ",{"type":42,"tag":127,"props":647,"children":648},{},[649],{"type":48,"value":650},"\"melt this matrix into source, target, value format and then draw a Sankey\"",{"type":48,"value":652},". It will reshape the data automatically.",{"type":42,"tag":51,"props":654,"children":655},{},[656,661,663,668],{"type":42,"tag":57,"props":657,"children":658},{},[659],{"type":48,"value":660},"Can I show more than two levels of nodes?",{"type":48,"value":662},"\nAbsolutely. Just make sure your data includes intermediate nodes — e.g. rows for A→B and B→C flows. The AI will infer the multi-layer structure. You can also ask for ",{"type":42,"tag":127,"props":664,"children":665},{},[666],{"type":48,"value":667},"\"a three-level Sankey showing department → sub-department → project\"",{"type":48,"value":669},".",{"type":42,"tag":51,"props":671,"children":672},{},[673,678,680,685,687,692],{"type":42,"tag":57,"props":674,"children":675},{},[676],{"type":48,"value":677},"How do I handle very small flows that clutter the diagram?",{"type":48,"value":679},"\nAsk the AI to ",{"type":42,"tag":127,"props":681,"children":682},{},[683],{"type":48,"value":684},"\"filter out flows below X units\"",{"type":48,"value":686}," or ",{"type":42,"tag":127,"props":688,"children":689},{},[690],{"type":48,"value":691},"\"group all flows smaller than 5% of total into an 'Other' category\"",{"type":48,"value":693},". This keeps the diagram readable.",{"type":42,"tag":51,"props":695,"children":696},{},[697,702,704,710],{"type":42,"tag":57,"props":698,"children":699},{},[700],{"type":48,"value":701},"Can I use this for website analytics or funnel analysis?",{"type":48,"value":703},"\nYes — export your funnel data as a CSV (step name, next step, user count) and ask for a Sankey showing the drop-off at each stage. This is a common use case in product analytics. See also the ",{"type":42,"tag":148,"props":705,"children":707},{"href":706},"/tools/ai-bar-chart-generator",[708],{"type":48,"value":709},"AI Bar Chart Generator",{"type":48,"value":711}," for simpler funnel comparisons.",{"title":7,"searchDepth":713,"depth":713,"links":714},2,[715,716,717,718,719,720,721,722],{"id":45,"depth":713,"text":49},{"id":97,"depth":713,"text":100},{"id":158,"depth":713,"text":161},{"id":259,"depth":713,"text":262},{"id":372,"depth":713,"text":375},{"id":503,"depth":713,"text":506},{"id":573,"depth":713,"text":576},{"id":622,"depth":713,"text":625},"markdown","content:tools:007.ai-sankey-diagram.md","content","tools/007.ai-sankey-diagram.md","tools/007.ai-sankey-diagram","md",{"loc":4},1775502471196]