I want to display multiple images with matplotlib.

Execution environment

Google Colaboratory

Preparing to load images with Google Colaboratory

python


from google.colab import files
from google.colab import drive
drive.mount('/content/drive')
img = cv2.imread("/content/drive/My Drive/Colab Notebooks/img/Lenna.bmp")
img2 = cv2.imread("/content/drive/My Drive/Colab Notebooks/img/Mandrill.bmp")

Loading the required libraries

python


import cv2 #opencv
import matplotlib.pyplot as plt 
%matplotlib inline

Check the code

python


#Create new window
fig = plt.figure()

#X the whole flg*Divide into Y and place the image at the plot position.
X = 2
Y = 2


#Display of img
imgplot = 1
ax1 = fig.add_subplot(X, Y, imgplot)
#Title setting
ax1.set_title("img",fontsize=20)
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))


#Display of img2
img2plot =  4
ax2 = fig.add_subplot(X, Y, img2plot)
#Title setting
ax2.set_title("img2",fontsize=20)
plt.imshow(cv2.cvtColor(img2, cv2.COLOR_BGR2RGB))

plt.show() #It was displayed without it.

result

q2.PNG

With this, it seems easy to write a comparison article of future operation results!

Recommended Posts

I want to display multiple images with matplotlib.
How to display images continuously with matplotlib Note
[Google Colab] I want to display multiple images side by side in tiles
I want to manually create a legend with matplotlib
I want to scrape images to learn
I want to do ○○ with Pandas
I want to debug with Python
I want to detect objects with OpenCV
How to title multiple figures with matplotlib
I want to blog with Jupyter Notebook
I want to pip install with PythonAnywhere
I want to analyze logs with Python
I want to play with aws with python
I want to display the progress bar
I want to embed Matplotlib in PySimpleGUI
Two ways to display multiple graphs in one image with matplotlib
For those who want to display images side by side as soon as possible with Python's matplotlib
I want to make matplotlib a dark theme
I want to analyze songs with Spotify API 2
(Matplotlib) I want to draw a graph with a size specified in pixels
I want to mock datetime.datetime.now () even with pytest!
I want to knock 100 data sciences with Colaboratory
[Python] How to draw multiple graphs with Matplotlib
I want to make a game with Python
I want to be an OREMO with setParam!
I want to analyze songs with Spotify API 1
I want to use Temporary Directory with Python2
I don't want to use -inf with np.log
#Unresolved I want to compile gobject-introspection with Python3
I want to use ip vrf with SONiC
I want to solve APG4b with Python (Chapter 2)
I want to start over with Django's Migrate
[I want to classify images using Tensorflow] (2) Let's classify images
I want to write to a file with Python
I want to display the progress in Python!
I want to solve the problem of memory leak when outputting a large number of images with Matplotlib
I want to display only different lines of a text file with diff
I want to convert an image to WebP with lollipop
Images created with matplotlib shift from dvi to pdf
I want to detect images of cats from Instagram
I want to detect unauthorized login to facebook with Jubatus (1)
I want to transition with a button in flask
I want to climb a mountain with reinforcement learning
How to display multiple images of galaxies in tiles
I want to inherit to the back with python dataclass
I want to work with a robot in python.
I want to split a character string with hiragana
I want to AWS Lambda with Python on Mac!
[TensorFlow] I want to process windows with Ragged Tensor
[ML Ops] I want to do multi-project with Python
I want to run a quantum computer with Python
I want to bind a local variable with lambda
I want to solve Sudoku (Sudoku)
Animate multiple graphs with matplotlib
I want to save a file with "Do not compress images in file" set in OpenPyXL
I want to be able to analyze data with Python (Part 3)
I want to specify another version of Python with pyvenv
I want to be able to analyze data with Python (Part 1)
I want to make a blog editor with django admin
I want to start a jupyter environment with one command
[NetworkX] I want to search for nodes with specific attributes