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']))))
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.
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.
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!
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With