This example uses the Dune Python client, which can be found
here and installed by doing
pip install dune-client
🎓 What is a Sankey Diagram? Sankey diagrams are flow diagrams in which the width
of the arrows or lines are proportional to the flow quantity they represent. They’re commonly used to depict the flow of energy, material, or costs between stages. So if you’ve been longing to visualize the movement of tokens between wallets, or how users transition between different app states, a Sankey diagram is your weapon of choice! For a deeper dive, check this article.Expected Data Input:
The key components for a Sankey are:- Source & Target: Indexes of where the flow starts and where it ends.
- Value: The quantity of flow between the source and target.
⛲ Let’s Generate that Sankey!
Here, we will walk through two examples. Example 1 is to graph a Sankey for a certain subset of RabbitHole Quests with Optimism grant, see how the questors are retained after 1-month period. Example 2 is to graph a Sankey for the token flow when swapping USDC for WETH using Uniswap if the swap is not direct. We will show you different ways to fetch data from Dune API in the process as well.1. Setup
Import all necessary libraries and authenticate to set up DuneClient.- Make sure you create have a .env file created with your ‘DUNE_API_KEY’ in
it! 2. Replace the path to your own directory in
os.chdir(...)
import pandas as pd import plotly.graph_objects as go import colorlover as