【问题标题】:Subplotting image using matplotlib使用 matplotlib 绘制图像
【发布时间】:2021-01-31 15:01:15
【问题描述】:

我使用文件夹中的cv2.imread 将几个图像存储为一个数组。我现在想使用子图显示文件夹中的几张图像。这是我尝试过的

w=10
h=10
fig=plt.figure(figsize=(8, 8))
columns = 4
rows = 5
for i in range(1, columns*rows +1):
    img = malaria_images[i]
    fig.add_subplot(rows, columns, i)
    plt.imshow(img)
plt.show()

然而结果看起来像这样。我不确定我哪里出错了。任何帮助,将不胜感激。谢谢

【问题讨论】:

  • 这个Plotting images side by side using matplotlib 回答你的问题了吗?
  • @sai 嗨。感谢您的答复。我尝试了所有方法,它仍然显示一个空网格
  • 您是否注意到轴的概念意味着每个子图的句柄?你不能使用plt.imshow
  • “malaria_images”变量的内容是文件路径还是图像?
  • @r-beginners 这是所有图片的列表

标签: python matplotlib cv2


【解决方案1】:

我已针对 cme​​ts 中的内容修改了您的解决方案。这不显示吗?

import matplotlib.pyplot as plt

w=10
h=10
#fig = plt.figure(figsize=(8, 8))
columns = 4
rows = 5

fig, axes = plt.subplots(rows, columns, figsize=(8, 8))

i = 0
for r in range(rows):
    for c in range(columns):
        axes[r,c].imshow(malaria_images[i])
        i += 1

plt.show()

【讨论】:

    猜你喜欢
    • 2017-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-20
    • 2012-04-10
    • 2015-04-24
    相关资源
    最近更新 更多