floweaver icon indicating copy to clipboard operation
floweaver copied to clipboard

how to save png when not running from jupyter

Open asoliverez opened this issue 6 years ago • 6 comments

Hi, I can use weave().to_widget().auto_save_png() to save a chart when running from a jupyter notebook

However, I have an application that runs multiple reports from a CLI and I want to include this one. I tried the same .auto_save_png() command as in jupyter, and it doesn't save a png. It doesn't do anything, not even throw an error.

Is it because I should be using a different widget outside of jupyter?

asoliverez avatar Apr 26 '18 11:04 asoliverez

Hi, the widget only works within the Jupyter notebook (the Sankey diagram is rendered to SVG/PNG in your browser).

To run outside Jupyter, if SVG is ok instead of PNG, probably the best way is to export to JSON using weave().to_json(filename, format="widget"), save to a file, then use svg-sankey.

$ svg-sankey test.json > test.svg

(see svg-sankey --help for options for margins, size etc)

This is working for me currently, but note that the JSON format is a work in progress (we're working on a JSON schema specification that will fix it) and is likely to change a bit.

If you need PNG you could then convert the SVG images using a tool like convert.

ricklupton avatar Apr 27 '18 17:04 ricklupton

Relatedly, Matplotlib contains a way to make Sankey plots, though I cannot say whether one is easier or harder to use, and Matplotlib's likely has no real maintainer. But if no interactivity is required, then that may be an option.

QuLogic avatar May 11 '18 22:05 QuLogic

Broken link to svg-sankey above: should be https://github.com/ricklupton/svg-sankey

nickynicolson avatar Jul 18 '18 11:07 nickynicolson

@nickynicolson Thanks, updated the link above.

ricklupton avatar Jul 23 '18 16:07 ricklupton

I installed svg-sankey following the instructions here and exported .json file for the quickstart example. But running svg-sankey on the example I get this error

$ svg-sankey --size 800,600 --margins 10,150 test.json > test.svg
/usr/lib/node_modules/svg-sankey/index.es5.js:134
    return d.data.value;
                 ^

TypeError: Cannot read property 'value' of undefined
    at /usr/lib/node_modules/svg-sankey/index.es5.js:134:18
    at /usr/lib/node_modules/svg-sankey/node_modules/d3-sankey-diagram/build/d3-sankey-diagram.cjs.js:1200:14
    at Array.forEach (native)
    at buildGraph (/usr/lib/node_modules/svg-sankey/node_modules/d3-sankey-diagram/build/d3-sankey-diagram.cjs.js:1191:15)
    at sankey (/usr/lib/node_modules/svg-sankey/node_modules/d3-sankey-diagram/build/d3-sankey-diagram.cjs.js:1293:13)
    at drawDiagram (/usr/lib/node_modules/svg-sankey/index.es5.js:158:12)
    at /usr/lib/node_modules/svg-sankey/index.es5.js:37:15
    at tryToString (fs.js:457:3)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:444:12)

Not sure how to resolve this. Thanks

anirban6908 avatar Aug 21 '19 18:08 anirban6908

I've got the same error. The lib doesn't working in Jupyter Lab and hasn't ability to save image without Jupyter. It looks like ship in the bottle 😄

Could anyone recommend the alternative library?

anki-code avatar Sep 30 '19 15:09 anki-code