Sankey Multiplot

I tried to create a multiplot in ipython-plotly containing a sankey-diagram.

In the example from the plotly subplot-page the layout is defined via anchors:

layout_all = dict(
width=1200,
height=2500,
autosize=False,
title=‘Sankey - Multiplot’,
margin = dict(t=100),
showlegend=False,
xaxis1=dict(axis, **dict(domain=[0, 1], anchor=‘y1’, showticklabels=False)),
#xaxis2=dict(axis, **dict(domain=[0, 1], anchor=‘y2’, showticklabels=False)),
yaxis1=dict(axis, **dict(domain=[0, 0.33], anchor=‘x1’, hoverformat=‘.2f’)),
#yaxis2=dict(axis, **dict(domain=[0.33, 0.66], anchor=‘x2’, hoverformat=‘.2f’)),
plot_bgcolor=‘rgba(228, 222, 249, 0.65)’

But it is not possible to assign “xaxis” or “yaxis” to a sankey-plot. What happens, is that the sankey plot spans the whole page, with subplots being merged inside. Would it be possible to specify a certain size for a sankey-diagram?
Link to Stack Overflow (no answers yet)

Hi @krisselack,

Yes this is possible. Trace types that can’t share axes with other traces (like sankey, parcoords, parcats, etc.) have a top-level domain property that is used to position them.

Here’s an example of positioning two sankey diagrams in a figure:

import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode()

data = [
    go.Sankey(
        domain={
            'x': [0, 0.45],
            'y': [0.55, 1],
        },
        node = dict(
          label = ["A1", "A2", "B1", "B2", "C1", "C2"],
          color = ["blue", "blue", "blue", "blue", "blue", "blue"]
        ),
        link = dict(
          source = [0,1,0,2,3,3],
          target = [2,3,3,4,4,5],
          value = [8,4,2,8,4,2]
        )),
    go.Sankey(
        domain={
            'x': [0.55, 1],
            'y': [0, 0.45],
        },
        node = dict(
          label = ["A1", "A2", "B1", "B2", "C1", "C2"],
          color = ["blue", "blue", "blue", "blue", "blue", "blue"]
        ),
        link = dict(
          source = [0,1,0,2,3,3],
          target = [2,3,3,4,4,5],
          value = [8,4,2,8,4,2]
        ))
]

layout =  dict(
    title = "Multi-Sankey Diagram",
)

fig = dict(data=data, layout=layout)
iplot(fig)

Hope that helps!
-Jon

1 Like

Ah, I see! I did not understand the domain parameters.