title: How do I make a simple, multi-level Sankey diagram with Plotly?
body: <p>I have a DataFrame like this that I'm trying to describe with a Sankey diagram:</p>
  <pre><code>import pandas as pd
  
  pd.DataFrame({
      'animal': ['dog', 'cat', 'cat', 'dog', 'cat'],
      'sex': ['male', 'female', 'female', 'male', 'male'],
      'status': ['wild', 'domesticated', 'domesticated', 'wild', 'domesticated'],
      'count': [8, 10, 11, 14, 6]
  })
  </code></pre>
  <pre><code>    animal  sex     status          count
  0   dog     male    wild            8
  1   cat     female  domesticated    10
  2   cat     female  domesticated    11
  3   dog     male    wild            14
  4   cat     male    domesticated    6
  </code></pre>
  <p>I'm trying to follow the steps in the <a href="https://plotly.com/python/sankey-diagram/" rel="nofollow noreferrer">documentation</a> but I can't make it work - I can't understand what branches where. Here's the example code:</p>
  <pre><code>import plotly.graph_objects as go
  
  fig = go.Figure(data=[go.Sankey(
      node = dict(
        pad = 15,
        thickness = 20,
        line = dict(color = &quot;black&quot;, width = 0.5),
        label = [&quot;A1&quot;, &quot;A2&quot;, &quot;B1&quot;, &quot;B2&quot;, &quot;C1&quot;, &quot;C2&quot;],
        color = &quot;blue&quot;
      ),
      link = dict(
        source = [0, 1, 0, 2, 3, 3], 
        target = [2, 3, 3, 4, 4, 5],
        value = [8, 4, 2, 8, 4, 2]
    ))])
  
  fig.update_layout(title_text=&quot;Basic Sankey Diagram&quot;, font_size=10)
  fig.show()
  </code></pre>
  <p>Here's what I'm trying to achieve:
  <a href="https://i.stack.imgur.com/l3mOl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l3mOl.png" alt="enter image description here" /></a></p>