- 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 fill an area within a polygon in Python using matplotlib?
To fill an area within a polygon in Python using matplotlib, we can take the following steps −
Steps
Set the figure size and adjust the padding between and around the subplots.
Create a figure and a set of subplots.
Get an instance of a polygon.
Get the generic collection of patches with iterable polygons.
Add a 'collection' to the axes' collections; return the collection.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt from matplotlib.collections import PatchCollection from matplotlib.patches import Polygon import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots(1) polygon = Polygon(np.random.rand(6, 2), closed=True, alpha=1) collection = PatchCollection([polygon]) ax.add_collection(collection) plt.show()
Output
It will produce the following output −
- Related Articles
- How to fill a polygon with a custom hatch in Matplotlib?
- How to fill the area under a step curve using pyplot? (Matplotlib)
- How to plot an area in a Pandas dataframe in Matplotlib Python?
- How to make a polygon radar (spider) chart in Python Matplotlib?
- Fill the area under a curve in Matplotlib python on log scale
- Program to find area of a polygon in Python
- How to add a clipping area on a Polygon using FabricJS?
- How to fill rainbow color under a curve in Python Matplotlib?
- How to plot an array in Python using Matplotlib?
- How to plot an angle spectrum using Matplotlib in Python?
- How to fill color below a curve in Matplotlib?
- How to draw a filled polygon using an imagefilledpolygon() function in PHP?
- How to find Kaprekar numbers within a given range using Python?
- How to plot MFCC in Python using Matplotlib?
- How to plot vectors in Python using Matplotlib?

Advertisements