-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.py
More file actions
43 lines (32 loc) · 889 Bytes
/
Graph.py
File metadata and controls
43 lines (32 loc) · 889 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
37
38
39
40
41
42
43
import matplotlib.pyplot as plt
print("Which graph do you want to draw?")
print("1. Line Graph")
print("2. Bar Graph")
print("3. Scatter Plot")
print("4. Pie Chart")
choice = int(input("Enter your choice (1-4): "))
# Asking data
x = input("Enter X values separated by space: ").split()
y = input("Enter Y values separated by space: ").split()
# Convert to numbers
x = [float(i) for i in x]
y = [float(i) for i in y]
plt.title("User Generated Graph")
plt.xlabel("X Values")
plt.ylabel("Y Values")
if choice == 1:
plt.plot(x, y, marker='o')
print("Drawing Line Graph...")
elif choice == 2:
plt.bar(x, y)
print("Drawing Bar Graph...")
elif choice == 3:
plt.scatter(x, y)
print("Drawing Scatter Plot...")
elif choice == 4:
plt.pie(y, labels=x, autopct='%1.1f%%')
print("Drawing Pie Chart...")
else:
print("Invalid choice!")
exit()
plt.show()