-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubplot.py
More file actions
50 lines (39 loc) · 1.17 KB
/
Copy pathsubplot.py
File metadata and controls
50 lines (39 loc) · 1.17 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
import matplotlib.pyplot as plt
import numpy as np
x = np.array([0, 1, 2, 3])
y1 = np.array([3, 8, 1, 10])
y2 = np.array([10, 20, 30, 40])
plt.figure(figsize=(14,8))
plt.suptitle("Multiple Subplots Examples", fontsize=16, fontweight='bold')
plt.subplot(1, 2, 1)
plt.plot(x, y1, marker='o', color='blue')
plt.title("SALES")
plt.xlabel("Quarter")
plt.ylabel("Units Sold")
plt.subplot(1, 2, 2)
plt.plot(x, y2, marker='s', color='green')
plt.title("INCOME")
plt.xlabel("Quarter")
plt.ylabel("Revenue ($)")
plt.figure(figsize=(8,6))
plt.suptitle("Stacked Plots Example", fontsize=16, fontweight='bold')
plt.subplot(2, 1, 1)
plt.plot(x, y1, color='purple', linestyle='--')
plt.title("SALES")
plt.xlabel("Quarter")
plt.ylabel("Units Sold")
plt.subplot(2, 1, 2)
plt.plot(x, y2, color='orange', linestyle='-.')
plt.title("INCOME")
plt.xlabel("Quarter")
plt.ylabel("Revenue ($)")
plt.tight_layout(rect=[0, 0, 1, 0.95])
plt.show()
plt.figure(figsize=(14,8))
plt.suptitle("2x3 Grid Subplots Example", fontsize=16, fontweight='bold')
for i in range(6):
plt.subplot(2, 3, i+1)
plt.plot(x, y1 if i % 2 == 0 else y2)
plt.title(f"Plot {i+1}")
plt.tight_layout(rect=[0, 0, 1, 0.95])
plt.show()