python - 使用 plt.imshow() 显示多张图片

标签 python matplotlib

如何使用 matlib 函数 plt.imshow(image) 显示多张图片?

例如我的代码如下:

for file in images:
    process(file)

def process(filename):
    image = mpimg.imread(filename)
    <something gets done here>
    plt.imshow(image)

我的结果显示只有最后处理过的图像有效地覆盖了其他图像

最佳答案

您可以使用以下设置框架来显示多个图像:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg

def process(filename: str=None) -> None:
    """
    View multiple images stored in files, stacking vertically

    Arguments:
        filename: str - path to filename containing image
    """
    image = mpimg.imread(filename)
    # <something gets done here>
    plt.figure()
    plt.imshow(image)

for file in images:
    process(file)

这将垂直堆叠图像

关于python - 使用 plt.imshow() 显示多张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41210823/

相关文章:

python - Plotly:如何在 Excel 中嵌入完全交互式的 Plotly 图形?

python - UnicodeEncodeError : 'latin-1' codec can't encode character '\u2013' (writing to PDF)

java - 为什么在 android 上使用 cryptography.io 和 java 完成的 RSA 身份验证不能一起工作?

python - python 中的 Men=mars 和 female=venus 符号

python - Jupyter Lab 交互图像展示 : issue with widgets arrangements using HBox

python - 如何正确使用matplotlib渲染图像直方图?

python - 引号之间的正则表达式向前看 - Python

python - 保护删除 ForeignKey

python - matplotlib 中的阴影图例线

python - 合并子图错误 - 'AxesSubplot' 对象没有属性 'get_gridspec'