- 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 to label a patch in matplotlib?
To label a patch in matplotlib, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Initialize the center of the rectangle patch.
Create a new figure or activate an existing figure.
Add an 'ax' to the figure as part of a subplot arrangement.
Add a 'rectangle' to the axes' patches; return the patch.
Place a legend on the figure.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import matplotlib.patches as patches plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = y = 0.1 fig = plt.figure() ax = fig.add_subplot(111) patch = ax.add_patch(patches.Rectangle((x, y), 0.5, 0.5, alpha=0.5, facecolor='red', label='Rectangle')) plt.legend(loc='upper right') plt.show()
Output
- Related Articles
- How to plot a 3D patch collection in matplotlib?
- How to rotate the rectangle patch in a plot using Matplotlib?
- How to control the border of a bar patch in matplotlib?
- How to label a line in Matplotlib (Python)?
- How to set different opacity of edgecolor and facecolor of a patch in Matplotlib?
- How to access axis label object in Matplotlib?
- How to display all label values in Matplotlib?
- How to customize the axis label in a Seaborn jointplot using Matplotlib?
- How to plot an emoji as a label for a bar in Matplotlib?
- How to change the font properties of a Matplotlib colorbar label?
- How to add a shared x-label and y-label to a plot created with Pandas' plot? (Matplotlib)
- How to print the Y-axis label horizontally in a Matplotlib/Pylab chart?
- How to set label for an already plotted line in Matplotlib?
- How to align axis label to the right or top in Matplotlib?
- How to use multiple font sizes in one label in Python Matplotlib?

Advertisements