

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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.
Steps
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.
Example
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[0], center[1], 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()
Output
- Related Questions & Answers
- 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?
Advertisements