Browse Source

多个子图

yufeng0528 4 years ago
parent
commit
f8ad39263c
1 changed files with 21 additions and 4 deletions
  1. 21 4
      draw/draw_util.py

+ 21 - 4
draw/draw_util.py

@@ -38,8 +38,25 @@ def drawScatterAndLine(p, q, w, b):
38 38
     plt.show()
39 39
 
40 40
 
41
+def mul_image():
42
+    plt.figure(1)  # 创建图表1
43
+    plt.figure(2)  # 创建图表2
44
+    ax1 = plt.subplot(211)  # 在图表2中创建子图1
45
+    ax2 = plt.subplot(212)  # 在图表2中创建子图2
46
+    x = np.linspace(0, 3, 100)
47
+    for i in range(5):
48
+        plt.figure(1)
49
+        plt.plot(x, np.exp(i * x / 3))
50
+        plt.sca(ax1)
51
+        plt.plot(x, np.sin(i * x))
52
+        plt.sca(ax2)
53
+        plt.plot(x, np.cos(i * x))
54
+    plt.show()
55
+
56
+
41 57
 if __name__ == '__main__':
42
-    heights = [1.5, 1.7]
43
-    weights = [43, 61]
44
-    drawScatter(heights,weights)
45
-    drawLine(1,2)
58
+    # heights = [1.5, 1.7]
59
+    # weights = [43, 61]
60
+    # drawScatter(heights,weights)
61
+    # drawLine(1,2)
62
+    mul_image()