我想在 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>"))
但它不输出图像,而是只显示 2 个图像的占位符:
我也尝试了以下内容:
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)
它们确实出现在弹出窗口中。
如何让 2 张图像在 iPython 中并排显示?
原文由 Kristada673 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以尝试使用
matplotlib
。您可以使用来自 matplotlib 的 —mpimg.imread
( 文档)将图像读取到numpy
数组,然后您可以使用subplots
最后imshow
_(文档_)显示图像。