
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Plot a Circle Inside a Rectangle in Matplotlib
To place a circle inside a rectangle, we can take the following steps −
Create a new figure or activate an existing figure using figure() method.
Add a subplot to the current axis.
Create a rectangle and a circle instance.
Add a rectangle to the current axis.
Add a circle to the current axis.
Scale x and y axes using xlim() and ylim() methods.
To display the figure, use show() method.
Example
import matplotlib from matplotlib import pyplot as plt, es plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111) rect = es.Rectangle((2, 2), 8, 5, color='yellow') circle = es.Circle((6, 4.5), radius=2, color='red') ax.add_(rect) ax.add_(circle) plt.xlim([-10, 10]) plt.ylim([-10, 10]) plt.axis('equal') plt.show()