- 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
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 Articles
- 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 to set the background color of a column in a matplotlib table?
- How can I set the background color on specific areas of a Pyplot figure using Matplotlib?
- How to set a line color to orange, and specify line markers in Matplotlib?
- How to set same color for markers and lines in a Matplotlib plot loop?
- How to set the border color of the dots in matplotlib's scatterplots?
- How can I get the color of the last figure in Matplotlib?
- How do I plot only a table in Matplotlib?
- How do you change the default font color for all text in Matplotlib?
- How to change axes background color in Matplotlib?
- How to set background color in jQuery?
- How to set background color in HTML?
- How to set font color in HTML?

Advertisements