-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreeCoordinatesGraph.py
More file actions
35 lines (27 loc) · 1 KB
/
ThreeCoordinatesGraph.py
File metadata and controls
35 lines (27 loc) · 1 KB
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
import matplotlib.pyplot as plt
import numpy as np
def main():
n = int(input("Enter the number of points: "))
x_coords = []
y_coords = []
z_coords = []
for i in range(n):
x = float(input(f"Enter x-coordinate of point {i + 1}: "))
y = float(input(f"Enter y-coordinate of point {i + 1}: "))
z = float(input(f"Enter z-coordinate of point {i + 1}: "))
x_coords.append(x)
y_coords.append(y)
z_coords.append(z)
colors = plt.cm.viridis(np.linspace(0, 1, n))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
sc = ax.scatter(x_coords, y_coords, z_coords, c=colors, edgecolor='k')
for i in range(n - 1):
ax.plot(x_coords[i:i + 2], y_coords[i:i + 2], z_coords[i:i + 2], color=colors[i])
ax.set_xlabel("X-axis")
ax.set_ylabel("Y-axis")
ax.set_zlabel("Z-axis")
ax.set_title("Graph for your data")
plt.show()
if __name__ == "__main__":
main()