如何在Jupyter笔记本(iPython)中并排显示2张图像?

克里斯塔达673:

我想在iPython中并排显示2个PNG图像。

我要做的代码是:

from IPython.display import Image, HTML, display

img_A = '\path\to\img_A.png'
img_B = '\path\to\img_B.png'

display(HTML("<table><tr><td><img src=img_A></td><td><img src=img_B></td></tr></table>"))

但是它不输出图像,而只显示两个图像的占位符:

在此处输入图片说明

我也尝试了以下方法:

s = """<table>
<tr>
<th><img src="%s"/></th>
<th><img src="%s"/></th>
</tr></table>"""%(img_A, img_B)
t=HTML(s)
display(t)

但是结果是一样的:

在此处输入图片说明

这些图像肯定在路径中,因为我通过在弹出窗口中显示它们进行了验证:

plt.imshow(img_A)
plt.imshow(img_B)

并且它们确实出现在弹出窗口中。

如何在iPython中并排显示2张图像?

学生:

您可以尝试使用matplotlib您可以numpy通过使用matplotlib中的mpimg.imreaddocumentation来读取图像到阵列,然后可以使用subplotsdocumentation)并为图形创建两列,最后imshowdocumetation)显示图像。

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from matplotlib import rcParams

%matplotlib inline

# figure size in inches optional
rcParams['figure.figsize'] = 11 ,8

# read images
img_A = mpimg.imread('\path\to\img_A.png')
img_B = mpimg.imread('\path\to\img_B.png')

# display images
fig, ax = plt.subplots(1,2)
ax[0].imshow(img_A);
ax[1].imshow(img_B);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在ipython笔记本中显示PIL图像

如何在jupyter笔记本中逐行绘制4000张图像?

如何在jupyter / ipython笔记本中的图形旁边显示文本段落

如何在ipython笔记本中重新加载图像?

如何在 Google Colab 中的笔记本中显示图像(如在 Anacondan Jupyter Notebook 中)?

如何在ipython笔记本中显示图形

如何在Jupyter笔记本中的R输出中显示图像表?

如何在Jupyter笔记本上并排显示YouTube视频和matplotlib图?

在IPython / Jupyter笔记本中显示行号

在IPython / Jupyter笔记本中显示行号

如何在Jupyter笔记本中显示一个单元格中的多个图像

如何在ipython / jupyter笔记本中修改Reveal.js幻灯片设置

如何在浏览器中增加Jupyter / ipython笔记本的单元格宽度?

在jupyter笔记本中显示图像网格

如何在一个IPython笔记本中多次显示同一matplotlib图?

如何在绘图时从jupyter笔记本中删除显示的matplotlib输出行

如何在Jupyter笔记本中显示Protein Data Bank PDB?

对于分类数据,如何在表而不是列表中显示结果?(Jupyter笔记本/ Python)

在jupyter笔记本中并排显示statsmodels plot_acf和plot_pacf

如何在Jupyter笔记本中嵌入gif?

如何在Jupyter笔记本中包装代码/文本

如何在Jupyter笔记本中配置缩进大小?

如何在Jupyter笔记本中对熊猫使用tqdm?

如何在jupyter笔记本中安装sympy

如何在Pycharm笔记本中停止Jupyter Server

如何在IPython笔记本中隐藏<matplotlib.lines.Line2D>

如何在Jupyter Ipython笔记本中注释掉多行?

如何设置ipython jupyter笔记本的单元格?

IPython / jupyter笔记本中的autoupdate模块