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,
And when handling images, I use imshow() to plot images, but how to plot multiple images together in different subplots with one figure?
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.
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.
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
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With