gpt4 book ai didi

python - 如何在一张图中显示多张图片?

转载 作者:IT老高 更新时间:2023-10-28 22:14:59 27 4
gpt4 key购买 nike

我使用 Python lib matplotlib 来绘制函数,并且我知道如何在一张图中绘制不同 subplot 中的多个函数,例如,enter image description here

在处理图像时,我使用 imshow() 来绘制图像,但是如何将多个图像一起绘制在不同的子图中用一个图?

最佳答案

documentation提供了一个示例(大约在页面下方的四分之三处):

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
fig = plt.figure()
a=fig.add_subplot(1,2,1)
img = mpimg.imread('../_static/stinkbug.png')
lum_img = img[:,:,0]
imgplot = plt.imshow(lum_img)
a.set_title('Before')
plt.colorbar(ticks=[0.1,0.3,0.5,0.7], orientation ='horizontal')
a=fig.add_subplot(1,2,2)
imgplot = plt.imshow(lum_img)
imgplot.set_clim(0.0,0.7)
a.set_title('After')
plt.colorbar(ticks=[0.1,0.3,0.5,0.7], orientation='horizontal')

# ---------------------------------------
# if needed inside the application logic, uncomment to show the images
# plt.show()

基本上,这与您通常使用 fig.add_subplot...

创建轴的操作相同

关于python - 如何在一张图中显示多张图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17111525/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com