python - 如何在 jupyter notebook 中并排显示图像
问题描述
我使用了以下代码,但它垂直显示图像。我希望它们在 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']))))
解决方案
使用 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)
推荐阅读
- exception-handling - Apache Camel MQTT - 消息代理关闭时不会引发异常
- php - 多个微型站点将作为一个登录
- c# - 表单执行串口命令,5秒后退出
- go - 以编程方式使用 Go-IPFS
- docker - ipv4 https 请求未转发到 docker 容器
- java - 如何通过 CronJob 从 Hybris 导出目录并通过分页导出到外部系统?
- angular - 带有 div 切换播放暂停的 ngx-youtube-player 角度组件
- php - PHP MySQL选择$id在字符串中的位置
- activejdbc - ActiveJDBC DBSpec - JUnit5 支持
- php - 更改多维数组PHP的索引