如何在 jupyter notebook 中并排显示图像

Har*_*sha 5 python jupyter-notebook

我使用了以下代码,但它垂直显示图像。我希望它们在 Jupyter Notebook 中并排显示。

display(Image.open(BytesIO(Item[iii][b'imgs'])))
display(Image.open(BytesIO(Item[jjj][b'imgs'])))
Run Code Online (Sandbox Code Playgroud)

我曾尝试使用此代码

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

但它是显示文本 display(Image.open(BytesIO(Item[jjj][b'imgs']))))

cos*_*bur 7

使用 ipywidgets 的布局功能,您可以做到

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)
Run Code Online (Sandbox Code Playgroud)


idn*_*vid 0

您可以使用子图。

import pylab 
pylab.subplot(1, 2, 1)
pylab.plot(range(10))
pylab.subplot(1, 2, 2)
pylab.plot(range(20))
Run Code Online (Sandbox Code Playgroud)