- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Drawing a rectangle with only border in Matplotlib
To draw a rectangle with only border in matplotlib, we can take the following steps−
- Create a figure and a set of subplots.
- Get the current axes, creating one if necessary.
- Add a patch, i.e., a rectangle to the current axes that is returned in step 2. Set the facecolor attribute to 'none'.
- 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 figure, _ = plt.subplots() ax = plt.gca() ax.add_patch(patches.Rectangle((.25, .25), .50, .50, edgecolor='orange', facecolor='none', linewidth=2)) plt.show()
Output
- Related Articles
- Drawing a network graph with networkX and Matplotlib
- How to display only a left and bottom box border in Matplotlib?
- Matplotlib – Drawing lattices and graphs with Networkx
- Plot a rectangle with an edgecolor in Matplotlib
- Drawing multiple figures in parallel in Python with Matplotlib
- How to create a Rectangle with border colour using FabricJS?
- Drawing circles on an image with Matplotlib and NumPy
- How to create a Rectangle with dash pattern border using FabricJS?
- Drawing average line in histogram in Matplotlib
- Drawing lines between two plots in Matplotlib
- Draw a border around subplots in Matplotlib
- Plotting distance arrows in technical drawing in Matplotlib
- Plot a circle inside a rectangle in Matplotlib
- Drawing multiple legends on the same axes in Matplotlib
- How to plot a rectangle inside a circle in Matplotlib?

Advertisements