- 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 get the center of a set of points using Python?
To get the center of a set of points, we can add all the elements of the list and divide that sum with the length of the list so that result could be the center of the corresponding axes.
Make two lists of data points.
Plot x and y data points using plot() method.
Get the center tuple of the x and y data points.
Place the center point on the plot.
Annotate the center as label for center of the x and y data points.
To display the figure, use show() method.
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [5, 1, 3, 2, 8] y = [3, 6, 1, 0, 5] plt.plot(x, y) center = sum(x)/len(x), sum(y)/len(y) plt.plot(center, center, marker='o') plt.annotate( "center", xy=center, xytext=(-20, 20), textcoords='offset points', ha='right', va='bottom', bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5), arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0')) plt.show()
- How to get the tags of the availability set using PowerShell?
- How to draw the largest polygon from a set of points in matplotlib?
- How to get stat of a file using Python?
- Find the Number of Triangles Formed from a Set of Points on Three Lines using C++
- Minimum number of points to be removed to get remaining points on one side of axis using C++.
- Program to group a set of points into k different groups in Python
- How to get the longitude and latitude of a city using Python?
- Python program to get all subsets of a given size of a set
- How to get first day of the week using Python?
- Python program to get all subsets of given size of a set
- How to get a set of elements containing all of the unique immediate children of each of the matched set of elements?
- How to get the fault domain count of the Azure Availability set using PowerShell?
- How to get the update domain count of the Azure Availability set using PowerShell?
- How to set the angle of rotation of a Circle using FabricJS?
- How to center align the items of a JComboBox in Java?