Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show multiple images in one figure?

I use Python lib matplotlib to plot functions, and I know how to plot several functions in different subplots in one figure, like this one, enter image description here

And when handling images, I use imshow() to plot images, but how to plot multiple images together in different subplots with one figure?

like image 452
Alcott Avatar asked Jun 14 '13 15:06

Alcott


People also ask

How do I plot multiple pictures?

MatPlotLib with PythonCreate random data using numpy. Add a subplot to the current figure, nrows=1, ncols=4 and at index=1. Display data as an image, i.e., on a 2D regular raster, using imshow() method with cmap="Blues_r". Add a subplot to the current figure, nrows=1, ncols=4 and at index=2.

How do I show multiple images in one figure Matlab?

You can use the imshow function with the MATLAB subplot function to display multiple images in a single figure window. For additional options, see Work with Image Sequences as Multidimensional Arrays. The Image Viewer app does not support this capability.


1 Answers

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

like image 83
mgilson Avatar answered Oct 05 '22 18:10

mgilson