
- 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 do I set color to Rectangle in Matplotlib?
To set color to a rectangle in matplotlib, we can take the following steps −
Create a figure or activate an existing figure using figure() method.
Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot() method.
A rectangle is defined via an anchor point with width and heights.
Add a rectangle patch to the plot.
Set the x and y limit using xlim() and ylim() method.
To display the figure, use show() method.
Example
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) rectangle = patches.Rectangle((0, 0), 3, 3, edgecolor='orange', facecolor="green", linewidth=7) ax.add_patch(rectangle) plt.xlim([-5, 5]) plt.ylim([-5, 5]) plt.show()
Output
- Related Questions & Answers
- How to set a Matplotlib rectangle edge to outside of specified width?
- How can I convert numbers to a color scale in Matplotlib?
- Using Colormaps to set the color of line in Matplotlib
- How can I set the background color on specific areas of a Pyplot figure using Matplotlib?
- How do I plot only a table in Matplotlib?
- How to set the background color of a column in a matplotlib table?
- How to set a line color to orange, and specify line markers in Matplotlib?
- How do I set the timezone of MySQL?
- How can I get the color of the last figure in Matplotlib?
- How do I print a Celsius symbol with Matplotlib?
- How do I adjust (offset) the colorbar title in Matplotlib?
- How do I specify an arrow-like linestyle in Matplotlib?
- How do I put a circle with annotation in matplotlib?
- How to plot a rectangle inside a circle in Matplotlib?
- How to add a text into a Rectangle in Matplotlib?
Advertisements