简体   繁体   中英

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.

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. 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

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. If i wanna plot 3 lines in 1 graph

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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