7

次のコードを使用しましたが、画像を垂直に表示しています。Jupyter Notebook に並べて表示したい。

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

このコードを使用してみました

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

しかし、それはテキストを表示していますdisplay(Image.open(BytesIO(Item[jjj][b'imgs']))))

4

4 に答える 4

9

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)
于 2018-07-13T00:20:03.073 に答える
1

2 つの画像を並べて表示する

import matplotlib.pyplot as plt
img1 = plt.imread('<PATH_TO_IMG1>')
img2 = plt.imread('<PATH_TO_IMG2>')

NUM_ROWS = 1
IMGs_IN_ROW = 2
f, ax = plt.subplots(NUM_ROWS, IMGs_IN_ROW, figsize=(16,6))

ax[0].imshow(img1)
ax[1].imshow(img2)

ax[0].set_title('image 1')
ax[1].set_title('image 2')

title = 'side by side view of images'
f.suptitle(title, fontsize=16)
plt.tight_layout()
plt.show()

ここに画像の説明を入力

于 2020-02-06T08:09:27.157 に答える