@@ -122,19 +122,33 @@ def update(frame):
122
122
# :class:`~matplotlib.image.AxesImage` object. The data in this object can also
123
123
# similarly be modified by using the `.image.AxesImage.set_data` method.
124
124
125
+
126
+ def f (x , y , mean , cov ):
127
+ dev_x = x - mean
128
+ dev_y = y - mean
129
+ maha = - 0.5 * (((x - mean )/ cov )** 2 + ((y - mean )/ cov )** 2 )
130
+ return (1 / (np .pi * cov )) * np .exp (maha )
131
+
125
132
fig , ax = plt .subplots ()
126
- rng = np .random .default_rng ()
127
133
128
- aximg = ax .imshow (rng .uniform (low = 0 , high = 1 , size = (10 , 10 )), cmap = "Blues" )
134
+ x , y = np .meshgrid (np .arange (- 1 , 1 , 0.01 ), np .arange (- 1 , 1 , 0.01 ))
135
+ mean = 0
136
+ cov = 0.1
137
+ data = f (x , y , mean , cov )
138
+ aximg = ax .imshow (data )
129
139
130
140
131
141
def update (frame ):
132
- data = rng .uniform (low = 0 , high = 1 , size = (10 , 10 ))
142
+ x , y = np .meshgrid (np .arange (- 1 , 1 , 0.01 ), np .arange (- 1 , 1 , 0.01 ))
143
+ mean = 0
144
+ cov = 0.01 * frame + 1e-6
145
+ data = f (x , y , mean , cov )
146
+
133
147
aximg .set_data (data )
134
148
return (aximg ,)
135
149
136
150
137
- ani = animation .FuncAnimation (fig = fig , func = update , frames = None , interval = 200 )
151
+ ani = animation .FuncAnimation (fig = fig , func = update , frames = None , interval = 100 )
138
152
plt .show ()
139
153
140
154
###############################################################################
@@ -146,18 +160,26 @@ def update(frame):
146
160
# list of artists is then converted frame by frame into an animation.
147
161
148
162
163
+ def f (x , y , mean , cov ):
164
+ dev_x = x - mean
165
+ dev_y = y - mean
166
+ maha = - 0.5 * (((x - mean )/ cov )** 2 + ((y - mean )/ cov )** 2 )
167
+ return (1 / (np .pi * cov )) * np .exp (maha )
168
+
149
169
fig , ax = plt .subplots ()
150
- ax .grid ()
151
- rng = np .random .default_rng ()
152
170
153
- x_frames = rng .uniform (low = 0 , high = 1 , size = (100 , 120 ))
154
- y_frames = rng .uniform (low = 0 , high = 1 , size = (100 , 120 ))
171
+ x , y = np .meshgrid (np .arange (- 1 , 1 , 0.01 ), np .arange (- 1 , 1 , 0.01 ))
172
+ mean = 0
173
+ cov = 0.1
174
+ data = f (x , y , mean , cov )
175
+ aximg = ax .imshow (data )
176
+
155
177
artists = [
156
- [ax .scatter ( x_frames [:, i ], y_frames [:, i ], c = "b" )]
157
- for i in range (x_frames . shape [ - 1 ] )
178
+ [ax .imshow ( f ( x , y , mean , 0.01 * frame + 1e-6 ) )]
179
+ for frame in range (120 )
158
180
]
159
181
160
- ani = animation .ArtistAnimation (fig = fig , artists = artists , repeat_delay = 1000 )
182
+ ani = animation .ArtistAnimation (fig = fig , artists = artists , interval = 100 )
161
183
plt .show ()
162
184
163
185
###############################################################################
0 commit comments