-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrapher.py
More file actions
37 lines (31 loc) · 898 Bytes
/
grapher.py
File metadata and controls
37 lines (31 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import matplotlib.pyplot as plt
def get_points():
points = []
print("Enter points as x,y pairs. Type 'done' to finish.")
while True:
user_input = input("Enter point (x,y): ")
if user_input.lower() == 'done':
break
try:
x, y = map(float, user_input.split(','))
points.append((x, y))
except ValueError:
print("Invalid input. Please enter the point as x,y.")
return points
def plot_points(points):
x_vals = [point[0] for point in points]
y_vals = [point[1] for point in points]
plt.scatter(x_vals, y_vals)
plt.title('Plot of Points')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.grid(True)
plt.show()
def main():
points = get_points()
if points:
plot_points(points)
else:
print("No points to plot.")
if __name__ == "__main__":
main()