ricklupton / floweaver

View flow data as Sankey diagrams
https://floweaver.readthedocs.io
MIT License
448 stars 89 forks source link

how to save png when not running from jupyter #34

Open asoliverez opened 6 years ago

asoliverez commented 6 years ago

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?

ricklupton commented 6 years ago

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.

QuLogic commented 6 years ago

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.

nickynicolson commented 6 years ago

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

ricklupton commented 6 years ago

@nickynicolson Thanks, updated the link above.

anirban6908 commented 5 years ago

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

anki-code commented 5 years ago

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?