Skip to content
Advertisement

How can I display an image from a file in Jupyter Notebook?

I would like to use an IPython notebook as a way to interactively analyze some genome charts I am making with Biopython’s GenomeDiagram module. While there is extensive documentation on how to use matplotlib to get graphs inline in IPython notebook, GenomeDiagram uses the ReportLab toolkit which I don’t think is supported for inline graphing in IPython.

I was thinking, however, that a way around this would be to write out the plot/genome diagram to a file and then open the image inline which would have the same result with something like this:

gd_diagram.write("test.png", "PNG")
display(file="test.png")

However, I can’t figure out how to do this – or know if it’s possible. So does anyone know if images can be opened/displayed in IPython?

Advertisement

Answer

Courtesy of this post, you can do the following:

from IPython.display import Image
Image(filename='test.png') 

(official docs)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement