

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to plot a rectangle inside a circle in Matplotlib?
To plot a rectangle inside a circle in matplotlib, 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.
Make a rectangle and a circle instance using Rectangle() and Circle() class.
Add a patch on the axes.
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, patches plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111) rect1 = patches.Rectangle((-2, -2), 4, 2, color='yellow') circle1 = matplotlib.patches.Circle((0, 0), radius=3, color='red') ax.add_patch(circle1) ax.add_patch(rect1) plt.xlim([-5, 5]) plt.ylim([-5, 5]) plt.axis('equal') plt.show()
Output
- Related Questions & Answers
- Plot a circle inside a rectangle in Matplotlib
- How to plot a circle in Matplotlib?
- Place text inside a circle in Matplotlib
- How to add text inside a plot in Matplotlib?
- How to plot a rectangle on a datetime axis using Matplotlib?
- Plot a rectangle with an edgecolor in Matplotlib
- How to rotate the rectangle patch in a plot using Matplotlib?
- How to draw axis lines inside a plot in Matplotlib?
- Plot a circle with an edgecolor in Matplotlib
- How to plot a half-black and half-white circle using Matplotlib?
- Plot a circle with an edgecolor and hatch in Matplotlib
- How to create a rectangle inside boxplot in base R?
- How to add a text into a Rectangle in Matplotlib?
- How to a plot stem plot in Matplotlib Python?
- How to draw a rectangle over a specific region in a Matplotlib graph?
Advertisements