Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display the images side by side in jupyter notebook

I have used the following code but it is displaying the images vertically. I want them to display side by side in a Jupyter Notebook.

display(Image.open(BytesIO(Item[iii][b'imgs'])))
display(Image.open(BytesIO(Item[jjj][b'imgs'])))

I have tried using this code

display(HTML("<table><tr><td>display(Image.open(BytesIO(Item[jjj][b'imgs'])))) 

but it is display the text display(Image.open(BytesIO(Item[jjj][b'imgs']))))

like image 647
Harsha Avatar asked Jul 12 '18 23:07

Harsha


People also ask

How to display two DataFrames side by side in Jupyter Notebook?

In this brief tutorial, we'll see how to display two and more DataFrames side by side in Jupyter Notebook. The first option for rendering two DataFrames side by side is to change Pandas styling methods. This solution is available since Pandas 0.17.

How to insert image in Jupyter Notebook?

The most user friendly way to insert image to Jupyter Notebook is to simply drag and drop the image to the notebook. It can be done only to Markdown cells. The image is encoded with Base64 and its text representation is included in the ipynb file.

Is it possible to display 2 images in a Jupiter notebook?

Although its a bit cumbersome to define so many elements just to display 2 images you can add a lot more functionality like sliders, dropdown menus as well as buttons making your Jupiter notebook more interactive. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research!

How can I display images in a NumPy array?

You can try using matplotlib. You can read image to numpy array by using mpimg.imread ( documentation) from matplotlib, then you can use subplots ( documentation) and for creating two columns for figures and finally imshow ( documetation) to display images. Show activity on this post.


1 Answers

Using layout features of ipywidgets you can do that

import ipywidgets as widgets
import IPython.display as display
## Read images from file (because this is binary, maybe you can find how to use ByteIO) but this is more easy
img1 = open('image1.jpeg', 'rb').read()
img2 = open('image2.jpeg', 'rb').read()
## Create image widgets. You can use layout of ipywidgets only with widgets.
## Set image variable, image format and dimension.
wi1 = widgets.Image(value=img1, format='png', width=300, height=400)
wi2 = widgets.Image(value=img2, format='png', width=300, height=400)
## Side by side thanks to HBox widgets
sidebyside = widgets.HBox([wi1, wi2])
## Finally, show.
display.display(sidebyside)
like image 168
cosmoscalibur Avatar answered Nov 08 '22 14:11

cosmoscalibur