How to view or save an <IPython.core.display.Image object> using plain python (not ipython)?

Question:

In the process of learning dask, I am trying to generate program graph visualizations using the “visualize” method/function. However, I am not working with a notebook. As far as I can tell, there is no way to have dask output these graphs to anything other than an IPython.core.display.Image object, which I don’t know how to view in regular python. For various reasons it’s impractical for me to run my code using IPython.

Is there any way to display these objects in a regular Python script/shell? Or at least, to save them to a standard image file on disk?

Thanks!

Asked By: 42bsk

||

Answers:

The .visualize method allows you to specify a filename to output to, and other parameters to be passed to dot/graphviz:

d.visualize(filename='dask.pdf')

produces a PDF file output instead of attempting an inline representation. Various other graphical formats are supported, such as PNG (although it may depend on how you installed graphviz).

You can also extract the image bytes from the Image instance

im = d.visualize()
open('output.png', 'wb').write(im.data)

which will be in PNG format (also given by im.format).

Answered By: mdurant
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.