46
46
import numpy as np
47
47
import matplotlib .pyplot as plt
48
48
import matplotlib .colors as colors
49
- from matplotlib .mlab import bivariate_normal
50
49
51
50
N = 100
52
51
X , Y = np .mgrid [- 3 :3 :complex (0 , N ), - 2 :2 :complex (0 , N )]
53
52
54
53
# A low hump with a spike coming out of the top right. Needs to have
55
54
# z/colour axis on a log scale so we see both hump and spike. linear
56
55
# scale only shows the spike.
57
- Z1 = bivariate_normal (X , Y , 0.1 , 0.2 , 1.0 , 1.0 ) + \
58
- 0.1 * bivariate_normal (X , Y , 1.0 , 1.0 , 0.0 , 0.0 )
56
+ Z1 = np .exp (- (X )** 2 - (Y )** 2 )
57
+ Z2 = np .exp (- (X * 10 )** 2 - (Y * 10 )** 2 )
58
+ Z = Z1 + 50 * Z2
59
59
60
60
fig , ax = plt .subplots (2 , 1 )
61
61
62
- pcm = ax [0 ].pcolor (X , Y , Z1 ,
63
- norm = colors .LogNorm (vmin = Z1 .min (), vmax = Z1 .max ()),
62
+ pcm = ax [0 ].pcolor (X , Y , Z ,
63
+ norm = colors .LogNorm (vmin = Z .min (), vmax = Z .max ()),
64
64
cmap = 'PuBu_r' )
65
65
fig .colorbar (pcm , ax = ax [0 ], extend = 'max' )
66
66
67
- pcm = ax [1 ].pcolor (X , Y , Z1 , cmap = 'PuBu_r' )
67
+ pcm = ax [1 ].pcolor (X , Y , Z , cmap = 'PuBu_r' )
68
68
fig .colorbar (pcm , ax = ax [1 ], extend = 'max' )
69
69
fig .show ()
70
70
89
89
90
90
N = 100
91
91
X , Y = np .mgrid [- 3 :3 :complex (0 , N ), - 2 :2 :complex (0 , N )]
92
- Z1 = ( bivariate_normal ( X , Y , 1. , 1. , 1.0 , 1.0 )) ** 2 \
93
- - 0.4 * ( bivariate_normal ( X , Y , 1.0 , 1.0 , - 1.0 , 0.0 )) ** 2
94
- Z1 = Z1 / 0.03
92
+ Z1 = np . exp ( - X ** 2 - Y ** 2 )
93
+ Z2 = np . exp ( - ( X - 1 ) ** 2 - ( Y - 1 ) ** 2 )
94
+ Z = ( Z1 - Z2 ) * 2
95
95
96
96
fig , ax = plt .subplots (2 , 1 )
97
97
98
- pcm = ax [0 ].pcolormesh (X , Y , Z1 ,
98
+ pcm = ax [0 ].pcolormesh (X , Y , Z ,
99
99
norm = colors .SymLogNorm (linthresh = 0.03 , linscale = 0.03 ,
100
100
vmin = - 1.0 , vmax = 1.0 ),
101
101
cmap = 'RdBu_r' )
102
102
fig .colorbar (pcm , ax = ax [0 ], extend = 'both' )
103
103
104
- pcm = ax [1 ].pcolormesh (X , Y , Z1 , cmap = 'RdBu_r' , vmin = - np .max (Z1 ))
104
+ pcm = ax [1 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , vmin = - np .max (Z ))
105
105
fig .colorbar (pcm , ax = ax [1 ], extend = 'both' )
106
106
fig .show ()
107
107
129
129
130
130
fig , ax = plt .subplots (2 , 1 )
131
131
132
- pcm = ax [0 ].pcolormesh (X , Y , Z1 , norm = colors .PowerNorm (gamma = 1. / 2. ),
132
+ pcm = ax [0 ].pcolormesh (X , Y , Z1 , norm = colors .PowerNorm (gamma = 0.5 ),
133
133
cmap = 'PuBu_r' )
134
134
fig .colorbar (pcm , ax = ax [0 ], extend = 'max' )
135
135
162
162
163
163
N = 100
164
164
X , Y = np .mgrid [- 3 :3 :complex (0 , N ), - 2 :2 :complex (0 , N )]
165
- Z1 = ( bivariate_normal ( X , Y , 1. , 1. , 1.0 , 1.0 )) ** 2 \
166
- - 0.4 * ( bivariate_normal ( X , Y , 1.0 , 1.0 , - 1.0 , 0.0 )) ** 2
167
- Z1 = Z1 / 0.03
165
+ Z1 = np . exp ( - X ** 2 - Y ** 2 )
166
+ Z2 = np . exp ( - ( X - 1 ) ** 2 - ( Y - 1 ) ** 2 )
167
+ Z = ( Z1 - Z2 ) * 2
168
168
169
169
fig , ax = plt .subplots (3 , 1 , figsize = (8 , 8 ))
170
170
ax = ax .flatten ()
171
171
# even bounds gives a contour-like effect
172
172
bounds = np .linspace (- 1 , 1 , 10 )
173
173
norm = colors .BoundaryNorm (boundaries = bounds , ncolors = 256 )
174
- pcm = ax [0 ].pcolormesh (X , Y , Z1 ,
174
+ pcm = ax [0 ].pcolormesh (X , Y , Z ,
175
175
norm = norm ,
176
176
cmap = 'RdBu_r' )
177
177
fig .colorbar (pcm , ax = ax [0 ], extend = 'both' , orientation = 'vertical' )
178
178
179
179
# uneven bounds changes the colormapping:
180
180
bounds = np .array ([- 0.25 , - 0.125 , 0 , 0.5 , 1 ])
181
181
norm = colors .BoundaryNorm (boundaries = bounds , ncolors = 256 )
182
- pcm = ax [1 ].pcolormesh (X , Y , Z1 , norm = norm , cmap = 'RdBu_r' )
182
+ pcm = ax [1 ].pcolormesh (X , Y , Z , norm = norm , cmap = 'RdBu_r' )
183
183
fig .colorbar (pcm , ax = ax [1 ], extend = 'both' , orientation = 'vertical' )
184
184
185
- pcm = ax [2 ].pcolormesh (X , Y , Z1 , cmap = 'RdBu_r' , vmin = - np .max (Z1 ))
185
+ pcm = ax [2 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , vmin = - np .max (Z ))
186
186
fig .colorbar (pcm , ax = ax [2 ], extend = 'both' , orientation = 'vertical' )
187
187
fig .show ()
188
188
207
207
208
208
N = 100
209
209
X , Y = np .mgrid [- 3 :3 :complex (0 , N ), - 2 :2 :complex (0 , N )]
210
- Z1 = ( bivariate_normal ( X , Y , 1. , 1. , 1.0 , 1.0 )) ** 2 \
211
- - 0.4 * ( bivariate_normal ( X , Y , 1.0 , 1.0 , - 1.0 , 0.0 )) ** 2
212
- Z1 = Z1 / 0.03
210
+ Z1 = np . exp ( - X ** 2 - Y ** 2 )
211
+ Z2 = np . exp ( - ( X - 1 ) ** 2 - ( Y - 1 ) ** 2 )
212
+ Z = ( Z1 - Z2 ) * 2
213
213
214
214
215
215
class MidpointNormalize (colors .Normalize ):
@@ -223,13 +223,14 @@ def __call__(self, value, clip=None):
223
223
x , y = [self .vmin , self .midpoint , self .vmax ], [0 , 0.5 , 1 ]
224
224
return np .ma .masked_array (np .interp (value , x , y ))
225
225
226
+
226
227
fig , ax = plt .subplots (2 , 1 )
227
228
228
- pcm = ax [0 ].pcolormesh (X , Y , Z1 ,
229
+ pcm = ax [0 ].pcolormesh (X , Y , Z ,
229
230
norm = MidpointNormalize (midpoint = 0. ),
230
231
cmap = 'RdBu_r' )
231
232
fig .colorbar (pcm , ax = ax [0 ], extend = 'both' )
232
233
233
- pcm = ax [1 ].pcolormesh (X , Y , Z1 , cmap = 'RdBu_r' , vmin = - np .max (Z1 ))
234
+ pcm = ax [1 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , vmin = - np .max (Z ))
234
235
fig .colorbar (pcm , ax = ax [1 ], extend = 'both' )
235
236
fig .show ()
0 commit comments