简体   繁体   English

在 python 中并排显示图像

[英]showing images side by side in python

I am showing image using this function我正在使用此功能显示图像

def draw_image(input_image, SIZE):
    im_input = cv2.imread(input_image)
    im_input_resized = cv2.resize(im_input, (SIZE, SIZE), interpolation=cv2.INTER_LINEAR)
    plt.imshow(cv2.cvtColor(im_input_resized, cv2.COLOR_BGR2RGB))
    plt.show()

I call this draw_image function from a caller that wants to show 1st 5 images(say) from a list.我从一个想要显示列表中的第 1 个 5 个图像(比如说)的调用者调用这个draw_image函数。

while i < top_k:
          draw_image(img[1], size)
          i +=1 

Now everytime the draw_image is called, the image is shown in a new row one by one.现在每次调用 draw_image 时,图像都会一张一张地显示在新行中。 But I need to show them in a single row.但我需要将它们显示在一行中。

Not sure how to do that.不知道该怎么做。 Please suggest.请建议。

I would do it with plt.subplot from matplotlib我会用来自 matplotlib 的 plt.subplot

fig, axs = plt.subplots(1,3)
axs[0].plot(draw_image(img[0], size))
axs[1].plot(draw_image(img[1], size))
axs[2].plot(draw_image(img[2], size))
plt.show()

This would create 3 separate plots in the same figure.这将在同一图中创建 3 个单独的图。 If i wanna plot 3 lines in 1 graph如果我想在 1 个图中绘制 3 条线

fig = plt.figure(figsize=(9, 3))
ax = fig.add_axes([0.05, 0.05, 0.75, 0.75])
ax.plot(draw_image(img[0], size))
ax.plot(draw_image(img[1], size))
ax.plot(draw_image(img[2], size))
plt.show()

I have not doublechecked code, but I would do something like that :)我没有仔细检查代码,但我会做类似的事情:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM