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

saving to disk as SVG #91

Closed
matthijsvk opened this issue Apr 5, 2023 · 4 comments
Closed

saving to disk as SVG #91

matthijsvk opened this issue Apr 5, 2023 · 4 comments

Comments

@matthijsvk
Copy link

matthijsvk commented Apr 5, 2023

Is your feature request related to a problem? Please describe.
If saving to disk, the default output format is PNG which is inefficient and low-resolution.
I couldn't find a way to save as SVG instead, though I'm sure graphviz supports this.

Describe the solution you'd like
add option "format=[svg|png]" that allows choosing the file format.
Alternatively, derive it from the filename, i.e. filename="model.svg" sets format=svg automatically.

Describe alternatives you've considered
This works:

model_graph = draw_graph(model, 
                        input_data=dummy_input, 
                        save_graph=True, 
                        directory="figures/")
model_graph.visual_graph.render(format='svg')

but this first saves a PNG and then the SVG as well, it would be cleaner if we had an option in the draw_graph() function itself

@mert-kurttutan
Copy link
Owner

Sorry for the late reply,
What you could is to turn off save graph option and then save it in svg format manually.
Since this could be done with just one line of code, I am not really willing to put it.
But if you or someone else provide nice PR, I would accept it.

@saifkhichi96
Copy link

saifkhichi96 commented Sep 1, 2023

@matthijsvk You can save the graph as SVG (or any other format supported by graphviz) like this:

graph = draw_graph(model, ...).visual_graph
graph_svg = graph.pipe(format='svg').decode('utf-8') # convert to binary data
with open(save_path + '.' + format, 'wb') as f:
    f.write(graph_svg)

@naik-amey
Copy link

How can I save as png?

@xdevfaheem
Copy link

s, u can @naik-amey. just set format arg to "png"

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

No branches or pull requests

5 participants