我有一个dataframe,它的列包含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发布于 2017-11-29 17:57:00
在Jupyter笔记本中显示图像网格的最好方法可能是使用matplotlib创建网格,因为您还可以使用imshow在matplotlib轴上绘制图像。
我使用的是3x165的网格,因为这是495。您可以随意更改网格的大小。
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发布于 2020-05-26 17:12:21
你的想法是将IPython.core.display与超文本标记语言结合使用,这是完成这类任务的最好方法。当涉及到绘制如此大量的图像时,matplotlib的效率非常低(特别是当您将它们作为URL时)。
我基于这个概念构建了一个小包--它叫做ipyplot
import ipyplot
images = data1['url'].values
labels = data1['id'].values
ipyplot.plot_images(images, labels, img_width=150)您将得到一个类似于以下内容的图:

发布于 2019-05-04 18:21:58
我只能通过“蛮力”来做到:
但是,我只能手动完成此操作:
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')
....不知道是不是有帮助
https://stackoverflow.com/questions/47508168
复制相似问题