且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在一个图中显示多个图像?

更新时间:2023-12-05 23:07:40

文档提供了一个示例(大约四分之三的时间)页面):

The documentation provides an example (about three quarters of the way down the page):

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

基本上,它和你一样通常用创建轴来完成 ...

Basically, it's the same as you do normally with creating axes with fig.add_subplot...