- 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
Drawing circles on an image with Matplotlib and NumPy
To draw a circle on an image with matplotlib and numpy, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Read an image from a file into an array.
Create x and y data points using numpy.
Create a figure and a set of subplots using subplots() method.
Display data as an image, i.e., on a 2D regular raster using imshow() method.
Turn off the axes.
Add patches on the current axes.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np from matplotlib.patches import Circle plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True img = plt.imread('bird.jpg') x = np.random.rand(5) * img.shape[1] y = np.random.rand(5) * img.shape[0] fig, ax = plt.subplots(1) ax.imshow(img) ax.axis('off') for xx, yy in zip(x, y): circ = Circle((xx, yy), 50, color='red') ax.add_patch(circ) plt.show()
Output
- Related Articles
- Overlay an image segmentation with Numpy and Matplotlib
- How to save an array as a grayscale image with Matplotlib/Numpy?
- Matplotlib – Drawing lattices and graphs with Networkx
- Drawing a network graph with networkX and Matplotlib
- Drawing borders around an image using OpenCV
- Drawing multiple legends on the same axes in Matplotlib
- Drawing an image in canvas using in JavaScript
- Drawing a rectangle with only border in Matplotlib
- Matplotlib figure to image as a numpy array
- Drawing multiple figures in parallel in Python with Matplotlib
- Plot numpy datetime64 with Matplotlib
- Linear regression with Matplotlib/Numpy
- Drawing an SVG file on an HTML5 canvas
- Gaussian filtering an image with NaN in Python Matplotlib
- Find Circles in an Image using OpenCV in Python

Advertisements