Sankey graphs blank when saved as SVG

Hi, as the title says whenever I’m saving a Sankey graph no matter if it’s large or small it always produces a blank svg. Is there a way to solve this issue? The graph display normally in my jupyter notebook but saves a blank svg (only title is visible).

I’m using plotly 3.6.1

def drawSankeyForAreaFlow(area_flow_data, log_index):
    sankeyData = getSankeyData(area_flow_data)

    data = dict(
        type='sankey',
        node = dict(
          pad = 30,
          line = dict(
            width = 0.5
          ),
          label = ['label 1', 'label 2', 'label 3', 'label 4', 'label 5', 'label 6', 'label 7', 'label 8', 'label 9', 'label 10', 'label 11', 'label 12', 'label 13', 'label 14', 'label 15', 'label 16'],
          color = ['#FF40C5', '#FF4A80', '#FF713D', '#FF9600', '#E5B200', '#A4C700', '#47D400', '#00DB65', '#00DFAE', '#00E1F5', '#00DEFF', '#00D6FF', '#00C7FF', '#58AEFF', '#EA8BFF', '#FF61FF', '#FF40C5']
        ),
        link = dict(
          source = [0, 2, 2, 2, 2, 2, 3, 4, 4, 4, 5, 8, 8, 9, 11, 12, 12, 14, 14, 15, 15, 15, 15, 15],
          target = [2, 4, 5, 11, 12, 15, 9, 4, 12, 15, 2, 2, 4, 0, 3, 0, 2, 8, 14, 0, 4, 12, 14, 15],
          value = [6, 2, 1, 1, 2, 2, 1, 1, 1, 5, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 3, 2, 1, 6]
    ))

    layout =  dict(
        title = "Sankey for log " + str(log_index),
        font = dict(
          size = 10
        )
    )

    fig=go.Figure(data=[data],layout=layout)
    pio.write_image(fig, "./output/graphs/" + "Sankey for log " + str(log_index) + ".svg")
    plotly.offline.iplot(fig, validate=False)

    return {'sources': sankeyData['sources'], 'targets': sankeyData['targets'], 'values': sankeyData['values']}

allSankeyData = []

for i, log in enumerate(logs):
    allSankeyData.append(drawSankeyForAreaFlow(log["properties"]["area_flow"], i))

Hi @aleks92,

Could you simplify your example a little bit and make it reproducible? This would mean adding the imports and data (logs is undefined for example).

Here’s a simple example I tried that is working properly for me with orca version 1.2.1 and plotly.py version 3.6.1.

import plotly.io as pio
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode()

data = dict(
    type='sankey',
    node = dict(
      pad = 15,
      thickness = 20,
      line = dict(
        color = "black",
        width = 0.5
      ),
      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 = "Basic Sankey Diagram",
    font = dict(
      size = 10
    )
)

fig = dict(data=[data], layout=layout)
pio.write_image(fig, 'sankey.svg')
iplot(fig)

-Jon

Hi Jon,

thanks for the help. I figured out that plotly doesn’t support circular references. At first, I thought that was only referring to a node referencing itself but now I realise it’s meant also for cases like “A->B, B->A”. My graphs got rendered in my notebooks for some reason (although not in the new notebook I created with your example) but they did not get saved.

Sorry for the inconvenience and thank you for the help.

Hi @aleks92,

Circular sankey support was just added recently in plotly.js 1.45.0 (See https://github.com/plotly/plotly.js/pull/3406), which was included with plotly.py 3.6.0. Are you using plotly.py >=3.6.0? I haven’t actually tried this from Python, but I expected that it would work fine.

-Jon

Hi @jmmease , yes I’m using the version 3.6.1. It stopped as soon as I added my data points which include cases like (A->B, B->C, C->A), (A->B, B->A) and sometimes also (A->A)

Aleks

Hi @aleks92,

I haven’t been directly involved in the Sankey updates, but I thought that all of the circular cases you mentioned should be supported now, both as HTML output and as SVG static images. Care to share a bug report at https://github.com/plotly/plotly.js/issues with an example that doesn’t work?

-Jon

Hi @jmmease yes sure I’ll report it :slight_smile:

-Aleks

Hi @jmmease for some unexplained reason, it started displaying the graphs again. However, the output images are still blank. Do you have an idea on how to solve or troubleshoot this issue? There are no errors in the console.

-Aleks