How to Make a Sankey Diagram with ChatGPT

Cody Schneider7 min read

Creating a Sankey diagram used to require either specialized software or some serious coding skills. Now, you can build one in minutes by simply telling ChatGPT what you want. This article will walk you through exactly how to prepare your data and write the right prompts to generate a Sankey diagram using AI, no coding experience necessary.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

What is a Sankey Diagram and When Should You Use One?

A Sankey diagram is a type of flow chart where the width of the arrows is proportional to the flow quantity. Think of it like a visual representation of a journey, showing how something moves from one stage to another. The thicker the line, the greater the amount flowing through that path.

This makes Sankey diagrams incredibly useful for visualizing things like:

  • Website User Flow: See how visitors move from your homepage to product pages, the blog, or the checkout page. You can quickly spot the most popular paths and where users drop off.
  • Marketing Funnel Analysis: Track how leads move from different channels (e.g., social media, paid ads, organic search) through various stages like "Lead", "MQL", and "Closed-Won".
  • Budget Allocation: Visualize how a company's total budget is distributed across different departments and specific projects.
  • Supply Chain Movement: Follow products from manufacturers to warehouses and finally to retail stores.

Essentially, if you want to understand the flow and volume of anything - be it users, money, or materials - a Sankey diagram is one of the clearest ways to show it.

Why Use ChatGPT to Build Your Charts?

The main reason to use ChatGPT is simple: it dramatically lowers the barrier to entry. Traditionally, creating a custom Sankey diagram involved writing code in a language like Python, using visualization libraries such as Plotly or Matplotlib. That meant you had to know how to install libraries, handle data structures, and debug code - a process that could take hours, especially for beginners.

ChatGPT changes the game. Instead of learning to code, you just need to know how to ask for what you want. It writes the code for you. This approach is powerful for a few reasons:

  • No Coding Expertise Needed: You can describe the chart you want in plain English. Just provide your data and specify the chart type, and ChatGPT handles the technical side.
  • It's Incredibly Fast: What might take an hour of manual coding and referencing documentation can be done in about two minutes. You ask, it generates, you use.
  • Iterative and Flexible: Don't like the colors? Want a different title? You can simply ask ChatGPT in a follow-up prompt to make adjustments. It's like having a data analyst you can talk to in real-time.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Preparing Your Data for a Sankey Diagram

Before you can prompt ChatGPT, you need to get your data in the right shape. This is the most important step. Sankey diagrams require data to be structured in a specific three-column format:

  1. Source: The starting point of a flow.
  2. Target: The ending point of a flow.
  3. Value: The quantity or weight of that specific flow.

Let's use a marketing campaign funnel as an example. Imagine you're tracking leads from different channels.

Your raw data might look scattered, but you need to consolidate it into this source-target-value format. Here’s what it would look like:

  • From ‘Facebook Ad’ (Source) to ‘Landing Page’ (Target), there are 500 visitors (Value).
  • From ‘Landing Page’ (Source) to ‘Demo Request’ (Target), there are 50 submissions (Value).
  • From ‘Google Ad’ (Source) to ‘Landing Page’ (Target), there are 800 visitors (Value).

And so on. For the full dataset, you just need a simple table or CSV file that has those three columns.

Example Data: Website User Flow

Let's work through a complete example. We’ll map out how users are navigating a website. Here’s our data, perfectly formatted for a Sankey diagram:

Source,Target,Value Organic Search,Homepage,5000 Paid Search,Homepage,3000 Social Media,Blog,2000 Homepage,About Us,1500 Homepage,Product Page,4000 Homepage,Pricing Page,2500 Blog,Product Page,500 Product Page,Pricing Page,1000 Product Page,Checkout,800

This data clearly shows the entry points (Organic, Paid, Social) and the subsequent paths users take, along with the volume of traffic for each path.

Step-by-Step Guide: How to Make a Sankey Diagram with ChatGPT

With our data ready, we can now create the diagram. The process involves generating Python code with ChatGPT and running it in a free tool called Google Colab.

Step 1: Get Your Environment Ready (with Google Colab)

You need a place to run the Python code ChatGPT gives you. The easiest way is with Google Colab. It's a free, cloud-based environment that runs code directly in your browser without any setup. Just head to colab.research.google.com and click "Create a new notebook." You'll see a code cell ready for you.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Step 2: Write a Clear Prompt for ChatGPT

Now, it's time to ask ChatGPT to build our chart. The key to a good result is a clear, specific prompt. Make sure to include:

  • The specific type of chart you want (Sankey diagram).
  • The technology to use (Python with the Plotly library).
  • Your data, formatted correctly.

Here is a template you can use:

Example Prompt:

Please write the Python code to create a Sankey diagram using the Plotly library.

Here is my data about website user flow in a CSV format:

Source,Target,Value Organic Search,Homepage,5000 Paid Search,Homepage,3000 Social Media,Blog,2000 Homepage,About Us,1500 Homepage,Product Page,4000 Homepage,Pricing Page,2500 Blog,Product Page,500 Product Page,Pricing Page,1000 Product Page,Checkout,800

The code should generate a self-contained HTML file or display the chart directly. Please provide the complete code I can run.

Step 3: Generate and Copy the Code

ChatGPT will process your request and generate a block of Python code. It will likely include steps to import the necessary library (Plotly), define the data, and then configure the Sankey diagram. All you need to do is click the "Copy code" button that appears in the top corner of the code block.

Step 4: Run the Code in Google Colab

Go back to your Google Colab notebook, paste the code you copied into the cell, and click the "Play" button on the left (or press Shift+Enter). You might see it install some packages first, but within a few seconds, it will execute the code.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Step 5: See Your Sankey Diagram

Success! Your interactive Sankey diagram will appear directly below the code cell. You can hover over the nodes and flows to see the values and paths. You’ve now visualized the journey of your website traffic, clearly showing how 10,000 visitors flowed through the site, with the "Product Page" being a major hub.

Customizing Your Diagram with Follow-Up Questions

The first version of your diagram is great, but what if you want to make some tweaks? This is where the conversational nature of AI shines. You don't need to learn a single line of Plotly's documentation. Just ask for changes.

Here are some examples of follow-up prompts you can use:

  • "Great, now can you add a title to the chart called 'Website Traffic Flow Analysis'?"
  • "Can you change the color scheme? Please use 'holly'." (Plotly has several predefined color schemes).
  • "Is it possible to change the color of the 'Checkout' node to green?"
  • "Please make the vertical gap between the nodes smaller."

For each request, ChatGPT will return a modified code block. Simply copy the new code, paste it back into Google Colab (either in a new cell or overwriting the old one), and run it again to see your changes instantly.

Final Thoughts

Using ChatGPT to translate plain English into code makes sophisticated data visualization tools like Sankey diagrams accessible to everyone. Instead of getting bogged down by technical complexities, you can focus on exploring your data, telling compelling stories, and finding insights that drive better decisions.

While using this copy-and-paste method with AI is fantastic for ad-hoc reports, we realize that building reports is often a continuous process. Constantly updating data and re-running code can become tedious. We built Graphed to solve this by creating a seamless, natural language interface for your live data. You can connect your Google Analytics, Shopify, HubSpot, and other tools, then just ask for a marketing funnel report or a sales performance dashboard without ever exporting a CSV or touching a line of code. Everything stays up-to-date automatically, letting you spend less time getting data and more time acting on it.

Related Articles