# Sankey Diagram

A **Sankey diagram** depicts **flows** of matter, energy or any other quantity, where the width of each flow pictured is based on its quantity.

## The Method To Use <a href="#the-method-to-use" id="the-method-to-use"></a>

The method is `s.plt.sankey()`

It must contain the following input variables:

```python
order: int, 
sources: str,
targets: str, 
values: str, 
data: List[Dict],
```

And accepts the following input variables as optional:

```python
option_modifications: Optional[Dict]
title: Optional[str] 
padding: Optional[List[int]]
rows_size: Optional[int] 
cols_size: Optional[int]
```

#### Video demonstration of the Sankey diagram <a href="#video-demonstration-of-the-sankey-diagram" id="video-demonstration-of-the-sankey-diagram"></a>

{% embed url="<https://www.loom.com/share/eb639b5b547a49b3a56d0a07960046a6>" %}
Sankey diagram settings and usage.
{% endembed %}

## Examples <a href="#examples" id="examples"></a>

### 1. Default Configuration <a href="#id-1.-default-configuration" id="id-1.-default-configuration"></a>

```python
data = [
    {
        "source": "a",
        "target": "a1",
        "value": 5
    },
    {
        "source": "a",
        "target": "a2",
        "value": 3
    },
    {
        "source": "a",
        "target": "b1",
        "value": 8
    },
    {
        "source": "b",
        "target": "b1",
        "value": 6
    },
    {
        "source": "b1",
        "target": "a1",
        "value": 1
    },
    {
        "source": "b1",
        "target": "c",
        "value": 2
    }
]

s.plt.sankey(
    data=data, order=0,
    sources='source', targets='target', values='value',
    rows_size=2, cols_size=12,
)
```

![The Sankey diagram is in the default configuration. ](/files/frUO2WGyg9ZC0Zm8Uqa9)

### 2. Customization And Context

```python
data = [
    {
        "source": "Chemical energy",
        "target": "light",
        "value": 15
    },
    {
        "source": "Chemical energy",
        "target": "electricity",
        "value": 3
    },
    {
        "source": "Chemical energy",
        "target": "heat",
        "value": 8
    },
    {
        "source": "Geothermal energy",
        "target": "heat",
        "value": 6
    },
    {
        "source": "heat",
        "target": "light",
        "value": 1
    },
    {
        "source": "heat",
        "target": "movement",
        "value": 2
    }
]

s.plt.sankey(
    data=data, order=0,
    sources='source', targets='target', values='value',
    rows_size=2, cols_size=9, padding='0,0,0,2',
    title='Chemical x Geothermal energies conversion',
)
```

![Note the space before the component using padding='0,0,0,2', and its size with cols\_size=9 .](/files/Tvxf3JxFNCcexHrFtN7N)

{% hint style="info" %}

### Featured Content

[Changing the Menu Path](/dev/building-web-app/menu/changing-the-menu-path.md)\
The `menu_path` can be modified.<br>

[Using the Grid](/dev/building-web-app/grid/using-the-grid.md)

It is possible to use any number of rows.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shimoku.com/dev/elements/charts/sankey-diagram.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
