- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 draw the largest polygon from a set of points in matplotlib?
To draw the largest polygon from a set of points in matplotlib, we can take the following steps −
- Import "Polygon" from matplotlib.patches.
- Set the figure size and adjust the padding between and around the subplots.
- Create a list of data points for the largest polygon.
- Get the polygon instance.
- Create a figure and a set of subplots.
- Add a polygon instance patch.
- Set the x and y scale limit.
- To display the figure, use show() method.
import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import Polygon plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True y = np.array([[1, 1], [0.5, 1.5], [2, 1], [1, 2], [2, 2]]) p = Polygon(y, facecolor='k') fig, ax = plt.subplots() ax.add_patch(p) ax.set_xlim([0, 3]) ax.set_ylim([0, 3]) plt.show()
It will produce the following output
- How to draw a polygon in HTML5 SVG?
- How to draw a polygon in OpenCV using Java?
- Draw a curve connecting two points instead of a straight line in matplotlib
- How to draw a filled polygon in OpenCV using Java?
- Draw a filled polygon using the OpenCV function fillPoly()
- How to draw axis in the middle of a figure in Matplotlib?
- How to draw a filled polygon using an imagefilledpolygon() function in PHP?
- Python Pandas - Draw a set of Horizontal point plots but do not draw lines to connect points with Seaborn
- How to draw a filled arc in Matplotlib?
- How to fill a polygon with a custom hatch in Matplotlib?
- How to draw an open polygon using the imageopenpolygon() function n PHP?
- How to draw a line outside of an axis in Matplotlib?
- How to draw more type of lines in Matplotlib?
- How to set the margins of a Matplotlib figure?
- Annotating points from a Pandas Dataframe in Matplotlib plot