Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to save png when not running from jupyter #34

Open
asoliverez opened this issue Apr 26, 2018 · 6 comments
Open

how to save png when not running from jupyter #34

asoliverez opened this issue Apr 26, 2018 · 6 comments

Comments

@asoliverez
Copy link

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 asoliverez changed the title how to save when not running from jupyter Apr 26, 2018
@ricklupton
Copy link
Owner

ricklupton commented Apr 27, 2018

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
Copy link
Contributor

QuLogic commented May 11, 2018

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
Copy link

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

@ricklupton
Copy link
Owner

@nickynicolson Thanks, updated the link above.

@anirban6908
Copy link

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
Copy link

anki-code commented Sep 30, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants