0

OpenCV.org tutorial has the following example:

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt

img = cv.imread('drawing.png')
rows,cols,ch = img.shape

pts1 = np.float32([[50,50],[200,50],[50,200]])
pts2 = np.float32([[10,100],[200,50],[100,250]])

M = cv.getAffineTransform(pts1,pts2)
dst = cv.warpAffine(img,M,(cols,rows))
plt.subplot(121),plt.imshow(img),plt.title('Input')
plt.subplot(122),plt.imshow(dst),plt.title('Output')
plt.show()

Here what is the role of subplot()? Docs define it as,

The Matplotlib subplot() function can be called to plot two or more plots in one figure. Matplotlib supports all kind of subplots including 2x1 vertical, 2x1 horizontal or a 2x2 grid.

The provided examples have the arguments telling the height vs length ratio and the third argument is used as the index. But it is quite unhelpful in my case.

tejasvi88
  • 635
  • 7
  • 15

1 Answers1

1

as per the documentation:

subplot(pos, **kwargs)

pos is a three digit integer, where the first digit is the number of rows, the second the number of columns, and the third the index of the subplot. i.e. fig.add_subplot(235) is the same as fig.add_subplot(2, 3, 5). Note that all integers must be less than 10 for this form to work.

Therefore plt.subplot(121) creates a figure with two Axes in a row (1 row, 2 columns) and makes the first one (leftmost) Axes the current axes.

Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75