- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between plt.show and cv2.imshow in Matplotlib?
A simple call to the imread method loads our image as a multi-dimensional NumPy array (one for each Red, Green, and Blue component, respectively) and imshow displays our image on the screen. Whereas, cv2 represents RGB images as multi-dimensional NumPy arrays, but in reverse order.
Steps
Set the figure size and adjust the padding between and around the subplots.
Initialize the filename.
Add a subplot to the current figure using nrows=1, ncols=2, and index=1.
Read the image using cv2.
Off the axes and show the figure in the next statement.
Add a subplot to the current figure using nrows=1, ncols=2, and index=2.
Read the image using plt.
Off the axes and show the figure in the next statement.
To display the figure, use show() method.
Example
import cv2 from matplotlib import pyplot as plt, image plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True filename = "bird.jpg" plt.subplot(121) img = cv2.imread(filename) plt.axis("off") plt.imshow(img) plt.title("with cv2") plt.subplot(122) img = image.imread(filename) plt.axis("off") plt.imshow(img) plt.title("with plt") plt.show()
Output
- Related Articles
- What is the difference between plt.close() and plt.clf() in Matplotlib?
- What is the difference between importing matplotlib and matplotlib.pyplot?
- Adjusting gridlines and ticks in Matplotlib imshow
- What is the difference between 'log' and 'symlog' in matplotlib?
- Plotting an imshow() image in 3d in Matplotlib
- How to add legend to imshow() in Matplotlib?
- Defining a discrete colormap for imshow in Matplotlib
- Remove white border when using subplot and imshow in Python Matplotlib
- What is the difference betweent set_xlim and set_xbound in Matplotlib?
- Change values on matplotlib imshow() graph axis
- Matplotlib – How to set xticks and yticks with imshow plot?
- How to apply a mask on the matrix in Matplotlib imshow?
- Matplotlib – Difference between plt.subplots() and plt.figure()
- What is the difference between drawing plots using plot, axes or figure in matplotlib?
- How to show two different colored colormaps in the same imshow Matplotlib?

Advertisements