7
7
import matplotlib .pyplot as plt
8
8
import matplotlib .cm as cm
9
9
10
- x = np .linspace (0 ,16 * np .pi ,1024 )
11
- y = np .linspace (- 1 ,1 ,512 )
12
- X ,Y = np .meshgrid (x ,y )
13
-
14
- data = np .zeros (X .shape )
15
-
16
- data [Y > 0 ]= np .cos (X [Y > 0 ])* Y [Y > 0 ]** 2
17
-
18
- for i ,val in enumerate (np .arange (- 1 ,1.1 ,0.2 )):
19
- if val < 0 :data [(X > (i * (50. / 11 )))* (Y < 0 )]= val
20
- if val > 0 :data [(X > (i * (50. / 11 )))* (Y < 0 )]= val * 2
21
-
22
- figsize = (16 ,10 )
23
- cmap = cm .gist_rainbow
24
-
25
- plt .figure (figsize = figsize )
26
- plt .pcolormesh (x ,y ,data ,cmap = cmap )
27
- plt .title ('Linear Scale' )
28
- plt .colorbar (format = '%.3g' )
29
- plt .xlim (0 ,16 * np .pi )
30
- plt .ylim (- 1 ,1 )
31
-
32
- plt .figure (figsize = figsize )
33
- norm = colors .ArbitraryNorm (fpos = (lambda x : x ** 0.2 ),
34
- fposinv = (lambda x : x ** 5 ),
35
- fneg = (lambda x : x ** 0.5 ),
36
- fneginv = (lambda x : x ** 2 ),
37
- center = 0.4 )
38
- plt .pcolormesh (x ,y ,data ,cmap = cmap ,norm = norm )
39
- plt .title ('Arbitrary norm' )
40
- plt .colorbar (ticks = norm .ticks (),format = '%.3g' )
41
- plt .xlim (0 ,16 * np .pi )
42
- plt .ylim (- 1 ,1 )
43
-
44
- plt .figure (figsize = figsize )
45
- norm = colors .PositiveArbitraryNorm (vmin = 0 ,
46
- fpos = (lambda x : x ** 0.5 ),
47
- fposinv = (lambda x : x ** 2 ))
48
- plt .pcolormesh (x ,y ,data ,cmap = cmap ,norm = norm )
49
- plt .title ('Positive arbitrary norm' )
50
- plt .colorbar (ticks = norm .ticks (),format = '%.3g' )
51
- plt .xlim (0 ,16 * np .pi )
52
- plt .ylim (- 1 ,1 )
53
-
54
- plt .figure (figsize = figsize )
55
- norm = colors .NegativeArbitraryNorm (vmax = 0 ,
56
- fneg = (lambda x : x ** 0.5 ),
57
- fneginv = (lambda x : x ** 2 ))
58
- plt .pcolormesh (x ,y ,data ,cmap = cmap ,norm = norm )
59
- plt .title ('Negative arbitrary norm' )
60
- plt .colorbar (ticks = norm .ticks (),format = '%.3g' )
61
- plt .xlim (0 ,16 * np .pi )
62
- plt .ylim (- 1 ,1 )
10
+ xmax = 16 * np .pi
11
+ x = np .linspace (0 , xmax , 1024 )
12
+ y = np .linspace (- 2 , 1 , 512 )
13
+ X , Y = np .meshgrid (x , y )
14
+
15
+ data = np .zeros (X .shape )
16
+
17
+
18
+ def gauss2d (x , y , a0 , x0 , y0 , wx , wy ):
19
+ return a0 * np .exp (- (x - x0 )** 2 / wx ** 2 - (y - y0 )** 2 / wy ** 2 )
20
+
21
+ N = 61
22
+ for i in range (N ):
23
+ data = data + gauss2d (X , Y , 2. * i / N , i *
24
+ (xmax / N ), - 0.25 , xmax / (3 * N ), 0.07 )
25
+ data = data - gauss2d (X , Y , 1. * i / N , i *
26
+ (xmax / N ), - 0.75 , xmax / (3 * N ), 0.07 )
27
+
28
+ data [Y > 0 ] = np .cos (X [Y > 0 ]) * Y [Y > 0 ]** 2
29
+
30
+ N = 61
31
+ for i , val in enumerate (np .linspace (- 1 , 1 , N )):
32
+ if val < 0 :
33
+ aux = val
34
+ if val > 0 :
35
+ aux = val * 2
36
+ data [(X > (i * (xmax / N ))) * (Y < - 1 )] = aux
37
+
38
+
39
+ cmap = cm .gist_rainbow
40
+
41
+ norms = [('Linear Scale' , None ),
42
+ ('Arbitrary norm' ,
43
+ colors .ArbitraryNorm (fpos = (lambda x : x ** 0.2 ),
44
+ fposinv = (lambda x : x ** 5 ),
45
+ fneg = (lambda x : x ** 0.5 ),
46
+ fneginv = (lambda x : x ** 2 ),
47
+ center = 0.4 )),
48
+ ('Positive arbitrary norm' ,
49
+ colors .PositiveArbitraryNorm (vmin = 0 ,
50
+ fpos = (lambda x : x ** 0.5 ),
51
+ fposinv = (lambda x : x ** 2 ))),
52
+ ('Negative arbitrary norm' ,
53
+ colors .NegativeArbitraryNorm (vmax = 0 ,
54
+ fneg = (lambda x : x ** 0.5 ),
55
+ fneginv = (lambda x : x ** 2 )))]
56
+
57
+
58
+ for label , norm in norms :
59
+ fig , ax = plt .subplots ()
60
+ cax = ax .pcolormesh (x , y , data , cmap = cmap , norm = norm )
61
+ ax .set_title (label )
62
+ ax .set_xlim (0 , xmax )
63
+ ax .set_ylim (- 2 , 1 )
64
+ if norm :
65
+ ticks = norm .ticks ()
66
+ else :
67
+ ticks = None
68
+ cbar = fig .colorbar (cax , format = '%.3g' , ticks = ticks )
69
+
70
+ plt .show ()
0 commit comments