Given an image the task here is to draft a python program using matplotlib to draw a rectangle on it. Matplotlib comes handy with rectangle() function which can be used for our requirement.
Syntax: Rectangle(xy, width, height, angle=0.0, **kwargs)
- xy: Lower left point to start the rectangle plotting
- width : width of the rectangle
- height: Height of the rectangle.
- angle: Angle of rotation of the rectangle.
- Import the necessary libraries.
- Insert and display the image.
- Create the figure and axes of the plot
- Add the patch to the Axes
- Display the image
Example 1: Draw a rectangle on an image
Example 2: Draw a filled rectangle
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course