回答編集履歴

1

サンプル追加

2018/09/02 06:41

投稿

magichan
magichan

スコア15898

test CHANGED
@@ -35,3 +35,59 @@
35
35
  plt.show()
36
36
 
37
37
  ```
38
+
39
+
40
+
41
+ ---
42
+
43
+
44
+
45
+ **【追記】**
46
+
47
+
48
+
49
+ ``set_color()`` を使う例
50
+
51
+
52
+
53
+ ```Python
54
+
55
+ import matplotlib.animation as anm
56
+
57
+ import matplotlib.pyplot as plt
58
+
59
+ import matplotlib.cm as cm
60
+
61
+ import numpy as np
62
+
63
+
64
+
65
+ fig = plt.figure()
66
+
67
+ ax = fig.add_subplot(1,1,1)
68
+
69
+ line, = ax.plot([], [])
70
+
71
+ ax.set_ylim(-1, 1)
72
+
73
+
74
+
75
+ def update(i, ax, line):
76
+
77
+ x = np.arange(i)
78
+
79
+ y = np.sin(x * 2 * np.pi / 100)
80
+
81
+ line.set_data(x, y)
82
+
83
+ line.set_color(cm.bwr(plt.Normalize(vmin=0, vmax=100)(i)))
84
+
85
+ ax.set_xlim(0, i)
86
+
87
+
88
+
89
+ ani = anm.FuncAnimation(fig, update, fargs=(ax, line), frames=100, interval=50)
90
+
91
+ plt.show()
92
+
93
+ ```