Cannot `show` PIL image after graphviz_draw
After calling graphviz_draw with filename=None, a PIL image object is returned, let's call it im. When calling im.show(), an error is raised because the image file was already deleted within the graphviz_draw function.
im = graphviz_draw(...)
im.show()
Error:
Traceback (most recent call last):
[...]
im = visualization.graphviz_draw(graph, image_type="svg", node_attr_fn=_node_to_attrs, edge_attr_fn=edge_attr_fn)
File "venv\lib\site-packages\retworkx\visualization\graphviz.py", line 197, in graphviz_draw
with Image.open(tmp_path) as temp_image:
File "venv\lib\site-packages\PIL\Image.py", line 3123, in open
raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file 'C:\\Users\\LAUREN~1\\AppData\\Local\\Temp\\tmp_y25gyfn\\graphviz_draw_9cd11dee-52ef-4685-bb59-559d2959a07c.svg'
The desired behavior would be to allow calling show on a returned PIL image object.
Thansk for catching this. I can reproduce the bug, here's a minimum example that triggers it
import retworkx as rx
from retworkx.visualization import mpl_draw, graphviz_draw
graph_1 = rx.generators.path_graph(2)
im = graphviz_draw(graph_1)
im.show()
Basically, we create a temporary file to store the image and then we make a copy. When we copy the image, the temporary file path is preserved and for some reason im.show() tries to access it.
In the meantime, if you are using Jupyter notebooks you can access the image with:
display(im)
Hi @IvanIsCoding, I'd like to contribute on this issue, you can assign to me if you'd like.