1

I have a loop where I want to render some sankeys to .png files.

Checking some docs here: https://nbviewer.jupyter.org/github/ricklupton/ipysankeywidget/blob/master/examples/Exporting%20Images.ipynb

I would expect sankey.save_svg('test.svg') to work.

From reading those docs, there's a caveat that trying to display and then save won't work, but I'm not trying to display, I just want to save a list of images. However I'm getting the same warnings.warn('No png image available! Try auto_save_png() instead?') error and cannot save.

If I run one line at a time, and return the sankey and let it display in the normal run of a python notebook, things work ok... So it seems there's something that happens when you let the notebook display a sankey that isn't happening when I'm just trying in a loop to render them to files.

from ipywidgets import Layout
from ipysankeywidget import SankeyWidget

def draw_one(use_case, limit=50):
    df = Cli.query_paths(use_case=use_case, limit=limit)

    layout = Layout(width="2000", height="500")
    fpath = f'./data/ignored/images/{use_case}-{limit}.png'

    # with or without: .auto_save_png(fpath)
    sankey = SankeyWidget(links=df.to_dict('records'), layout=layout) 
    sankey.save_png(fpath)

cases = [
'INTL',
'PAC',
]

def loop():
    for use_case in cases:
        print('sk:', use_case)
        sk = draw_one(use_case, limit=50)

loop()
dcsan
  • 11,333
  • 15
  • 77
  • 118

0 Answers0