-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
62 lines (49 loc) · 1.41 KB
/
Copy pathplot.py
File metadata and controls
62 lines (49 loc) · 1.41 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# import matplotlib.pyplot as plt
# import numpy as np
# xpoints = np.array([1,6,7,9,15])
# ypoints = np.array([34,66,99,112,230])
# plt.plot(xpoints,ypoints,'o')
# plt.show()
# plt.plot(xpoints,ypoints)
# plt.show()
# plt.plot(ypoints)
# plt.grid(True)
# plt.show()
import matplotlib.pyplot as plt
import numpy as np
# Data
x = np.array([1, 6, 7, 9, 15])
y1 = np.array([34, 66, 99, 112, 230])
y2 = np.array([20, 50, 80, 120, 200])
# Figure Size
plt.figure(figsize=(12,6))
# ---- Subplot 1: Scatter + Annotate ----
plt.subplot(1,2,1) # 1 row, 2 cols, plot 1
plt.scatter(x, y1, color='red', s=80, label='y1 points') # Scatter
plt.title("Scatter Plot with Annotations")
plt.xlabel("X Values")
plt.ylabel("Y Values")
plt.grid(True)
# Annotate points
for i, j in zip(x, y1):
plt.text(i, j+5, f'({i},{j})') # +5 to lift text above point
plt.legend()
# ---- Subplot 2: Multiple Lines ----
plt.subplot(1,2,2) # plot 2
plt.plot(x, y1, color='blue', linestyle='-', marker='o', markersize=8, label='Line 1')
plt.plot(x, y2, color='green', linestyle='--', marker='x', markersize=8, label='Line 2')
plt.title("Multiple Lines with Grid & Legend")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.grid(True)
plt.legend()
plt.xlim(0, 20)
plt.ylim(0, 250)
# Annotate points
for i, j in zip(x, y1):
plt.text(i, j+5, f'{j}')
for i, j in zip(x, y2):
plt.text(i, j+5, f'{j}')
# Show all plots
plt.tight_layout() # adjust spacing
plt.show()