10
10
import numpy as np
11
11
12
12
from matplotlib import cbook
13
- import matplotlib .colors
14
13
from mpl_toolkits .axes_grid1 import ImageGrid
15
14
16
15
@@ -35,16 +34,11 @@ def add_inner_title(ax, title, loc, **kwargs):
35
34
extent = extent [0 ], extent [1 ]/ 3. , extent [2 ], extent [3 ]
36
35
37
36
# *** Demo 1: colorbar at each axes ***
38
- grid = ImageGrid (fig , 211 , # similar to subplot(211)
39
- nrows_ncols = (1 , 3 ),
40
- axes_pad = 0.05 ,
41
- label_mode = "1" ,
42
- share_all = True ,
43
- cbar_location = "top" ,
44
- cbar_mode = "each" ,
45
- cbar_size = "7%" ,
46
- cbar_pad = "1%" ,
47
- )
37
+ grid = ImageGrid (
38
+ # 211 = at the position of fig.add_subplot(211)
39
+ fig , 211 , nrows_ncols = (1 , 3 ), axes_pad = 0.05 , label_mode = "1" , share_all = True ,
40
+ cbar_location = "top" , cbar_mode = "each" , cbar_size = "7%" , cbar_pad = "1%" )
41
+ grid [0 ].set (xticks = [- 2 , 0 ], yticks = [- 2 , 0 , 2 ])
48
42
49
43
for i , (ax , z ) in enumerate (zip (grid , ZS )):
50
44
im = ax .imshow (z , origin = "lower" , extent = extent )
@@ -54,46 +48,22 @@ def add_inner_title(ax, title, loc, **kwargs):
54
48
cb .set_ticks ([- 1 , 0 , 1 ])
55
49
56
50
for ax , im_title in zip (grid , ["Image 1" , "Image 2" , "Image 3" ]):
57
- t = add_inner_title (ax , im_title , loc = 'lower left' )
58
- t .patch .set_alpha (0.5 )
59
-
60
- for ax , z in zip (grid , ZS ):
61
- ax .cax .toggle_label (True )
62
-
63
- grid [0 ].set_xticks ([- 2 , 0 ])
64
- grid [0 ].set_yticks ([- 2 , 0 , 2 ])
51
+ add_inner_title (ax , im_title , loc = 'lower left' )
65
52
66
53
# *** Demo 2: shared colorbar ***
67
- grid2 = ImageGrid (fig , 212 ,
68
- nrows_ncols = (1 , 3 ),
69
- axes_pad = 0.05 ,
70
- label_mode = "1" ,
71
- share_all = True ,
72
- cbar_location = "right" ,
73
- cbar_mode = "single" ,
74
- cbar_size = "10%" ,
75
- cbar_pad = 0.05 ,
76
- )
77
-
78
- grid2 [0 ].set_xlabel ("X" )
79
- grid2 [0 ].set_ylabel ("Y" )
80
-
81
- vmax , vmin = np .max (ZS ), np .min (ZS )
82
- norm = matplotlib .colors .Normalize (vmax = vmax , vmin = vmin )
54
+ grid2 = ImageGrid (
55
+ fig , 212 , nrows_ncols = (1 , 3 ), axes_pad = 0.05 , label_mode = "1" , share_all = True ,
56
+ cbar_location = "right" , cbar_mode = "single" , cbar_size = "10%" , cbar_pad = 0.05 )
57
+ grid2 [0 ].set (xlabel = "X" , ylabel = "Y" , xticks = [- 2 , 0 ], yticks = [- 2 , 0 , 2 ])
83
58
59
+ clim = (np .min (ZS ), np .max (ZS ))
84
60
for ax , z in zip (grid2 , ZS ):
85
- im = ax .imshow (z , norm = norm , origin = "lower" , extent = extent )
61
+ im = ax .imshow (z , clim = clim , origin = "lower" , extent = extent )
86
62
87
63
# With cbar_mode="single", cax attribute of all axes are identical.
88
64
ax .cax .colorbar (im )
89
- ax .cax .toggle_label (True )
90
65
91
66
for ax , im_title in zip (grid2 , ["(a)" , "(b)" , "(c)" ]):
92
- t = add_inner_title (ax , im_title , loc = 'upper left' )
93
- t .patch .set_ec ("none" )
94
- t .patch .set_alpha (0.5 )
95
-
96
- grid2 [0 ].set_xticks ([- 2 , 0 ])
97
- grid2 [0 ].set_yticks ([- 2 , 0 , 2 ])
67
+ add_inner_title (ax , im_title , loc = 'upper left' )
98
68
99
69
plt .show ()
0 commit comments