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

前端 未结 11 1140
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 01:03

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 doc

11条回答
  •  [愿得一人]
    2020-11-28 01:24

    Courtesy of this page, I found this worked when the suggestions above didn't:

    import PIL.Image
    from cStringIO import StringIO
    import IPython.display
    import numpy as np
    def showarray(a, fmt='png'):
        a = np.uint8(a)
        f = StringIO()
        PIL.Image.fromarray(a).save(f, fmt)
        IPython.display.display(IPython.display.Image(data=f.getvalue()))
    

提交回复
热议问题