LoginSignup
56
34

More than 5 years have passed since last update.

jupyter notebookで画像を表示させたいだけならば、`IPython.display`モジュールのメソッドを使うべし

Posted at

本題

google検索にて、jupyter notebook 画像表示とすると、pillow(PIL)を用いて画像表示するとか、matplotlibで画像表示するとか言う方法がトップに来ます。

それよりも、notebookで(出力)画像を表示するだけならばIPython.displayモジュールのdisplay_*関数がおすすめです。

from IPython.display import Image, display_png
# png_file: str
display_png(Image(png_file))

とするだけ!1 もちろんmatplotlib使わないので、%matplotlib inlineも不要ですよ:ok_hand_tone1:

jpegとか、pdfも扱えるようです。詳しくは、APIを見てください。 https://ipython.org/ipython-doc/3/api/generated/IPython.display.html


  1. と言うより最近はもっぱら、画像やtableを表示するためだけしかnotebook使ってないですね。。 

56
34
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
56
34