首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在jupyter notebook中显示图像网格

在jupyter notebook中显示图像网格
EN

Stack Overflow用户
提问于 2017-11-27 17:58:57
回答 3查看 9.2K关注 0票数 9

我有一个dataframe,它的列包含495行URL。我想在jupyter notebook中以图像网格的形式显示这些URL。数据帧的第一行如下所示。任何帮助都是非常感谢的。

代码语言:javascript
复制
id           latitude     longitude     owner             title                          url
23969985288 37.721238   -123.071023 7679729@N07 There she blows!    https://farm5.staticflickr.com/4491/2396998528...

我已经尝试了以下方法,

代码语言:javascript
复制
from IPython.core.display import display, HTML
for index, row in data1.iterrows():
  display(HTML("<img src='%s'>"%(i["url"])))

但是,运行上述代码会显示以下消息

代码语言:javascript
复制
> TypeError                         Traceback (most recent call last)
<ipython-input-117-4c2081563c17> in <module>()
      1 from IPython.core.display import display, HTML
      2 for index, row in data1.iterrows():
----> 3   display(HTML("<img src='%s'>"%(i["url"])))

TypeError: string indices must be integers
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-11-29 17:57:00

在Jupyter笔记本中显示图像网格的最好方法可能是使用matplotlib创建网格,因为您还可以使用imshowmatplotlib轴上绘制图像。

我使用的是3x165的网格,因为这是495。您可以随意更改网格的大小。

代码语言:javascript
复制
import urllib
f, axarr = plt.subplots(3, 165)
curr_row = 0
for index, row in data1.iterrows():
     # fetch the url as a file type object, then read the image
     f = urllib.request.urlopen(row["url"])
     a = plt.imread(f)

     # find the column by taking the current index modulo 3
     col = index % 3
     # plot on relevant subplot
     axarr[col,curr_row].imshow(a)
     if col == 2:
         # we have finished the current row, so increment row counter
         curr_row += 1
票数 7
EN

Stack Overflow用户

发布于 2020-05-26 17:12:21

你的想法是将IPython.core.display与超文本标记语言结合使用,这是完成这类任务的最好方法。当涉及到绘制如此大量的图像时,matplotlib的效率非常低(特别是当您将它们作为URL时)。

我基于这个概念构建了一个小包--它叫做ipyplot

代码语言:javascript
复制
import ipyplot

images = data1['url'].values
labels = data1['id'].values

ipyplot.plot_images(images, labels, img_width=150)

您将得到一个类似于以下内容的图:

票数 10
EN

Stack Overflow用户

发布于 2019-05-04 18:21:58

我只能通过“蛮力”来做到:

但是,我只能手动完成此操作:

代码语言:javascript
复制
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

%matplotlib inline

img1=mpimg.imread('Variable_8.png')
img2=mpimg.imread('Variable_17.png')
img3=mpimg.imread('Variable_18.png')
          ...

fig, ((ax1, ax2, ax3), (ax4,ax5,ax6)) = plt.subplots(2, 3, sharex=True, sharey=True) 

ax1.imshow(img1)
ax1.axis('off')
ax2.imshow(img2)
ax2.axis('off')
   ....

不知道是不是有帮助

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47508168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档