Inserting and Resizing Images in IPython Notebook (Python and R)

Adding Images in IPython Notebook (short article)

Rahul Raoniar
The Researchers’ Guide
2 min readMay 22, 2020

--

Photo by Marvin Meyer on Unsplash

The current article is about a problem that I had faced when started learning data analysis in the IPython notebook. The problem is about loading an image in IPython notebook so that I could present codes with better visual representation (i.e., with images).

I have searched for several solutions on different websites. Different people have reported different mechanisms and libraries in Q & A blogs. After trying different solutions I have found two possible solutions for both Python and R that works perfectly.

Python solution

Let’s first discuss the solution when running Python in the IPython notebook. We could use the Image class of IPython.display to load and display a local image in the IPython notebook.

Here, I have used the Image( ) function, where one needs to supply the filename i.e., the location path for the image file. Additionally, we can vary the width and height to adjust the image size.

Photo by Aleks Dorohovich on Unsplash

R Solution

Let’s next discuss the R solution for IPython notebook. For R, IRdisplay library is the best available option to load a local image.

Here, I have used the display_png( ) function, where one needs to supply the filename i.e., the location path for the image file. Additionally, we can vary the width and height to adjust the image size.

Photo by Aleks Dorohovich on Unsplash

I hope this would help.

Rahul Raoniar

--

--

Rahul Raoniar
The Researchers’ Guide

👨‍🔬Researcher | 🐍Python | 🧮Rstats | 👨‍🔬Stata | 📊Data Science & ML | 👩‍💻Blogger | ▶YouTuber | 🌐Website: https://www.rahulraoniar.com/