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

标签 python html matplotlib jupyter-notebook

我有一个数据框,其中一列包含 495 行 URL。我想在 jupyter notebook 中将这些 URL 显示为图像网格。数据框的第一行显示在这里。任何帮助表示赞赏。

id           latitude     longitude     owner             title                          url
23969985288 37.721238   -123.071023 7679729@N07 There she blows!    https://farm5.staticflickr.com/4491/2396998528...

我试过下面的方法,

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

但是,上面代码的运行会显示消息

> 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

最佳答案

您将 IPython.core.display 与 HTML 一起使用的想法是恕我直言,是完成此类任务的最佳方法。 matplotlib 在绘制如此大量的图像时效率极低(尤其是当您将它们作为 URL 时)。
我根据这个概念构建了一个小包 - 它叫做 ipyplot

import ipyplot

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

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

你会得到类似这样的情节:
enter image description here

关于python - 在 jupyter 笔记本中显示图像网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47508168/

相关文章:

python - Azure 网站 Kudu REST API - Python 中的身份验证

python - 如何让 python 忽略垃圾收集的对象?

python - 导入错误: cannot import name 'my_function' from 'abc'

python - 如何绘制不均匀数据点之间均匀间距的直方图?

python - 在 ipython 笔记本中使用 matplotlib 内联时如何禁用 bbox_inches ='tight'

python - 读取 JSON 文件有时有效有时无效 (Python)

html - 如何在我的 bigcartel 侧边栏中添加社交媒体图标?

javascript - 如何提取 HTML 文档中的 javascript 链接?

html - 如何使用 Flutter Mailer Package 发送复杂的邮件

python - 绘制 pandas 列的直方图