3232
3333fig , ax = plt .subplots (2 , 1 )
3434
35- pcm = ax [0 ].pcolor (X , Y , Z , cmap = 'PuBu_r' , shading = 'nearest' )
36- fig . colorbar ( pcm , ax = ax [0 ], extend = 'max' , label = 'linear scaling' )
35+ ax [0 ].pcolor (X , Y , Z , cmap = 'PuBu_r' , shading = 'nearest' )
36+ ax [0 ]. colorbar ( extend = 'max' , label = 'linear scaling' )
3737
38- pcm = ax [1 ].pcolor (X , Y , Z , cmap = 'PuBu_r' , shading = 'nearest' ,
39- norm = colors .LogNorm (vmin = Z .min (), vmax = Z .max ()))
40- fig . colorbar ( pcm , ax = ax [1 ], extend = 'max' , label = 'LogNorm' )
38+ ax [1 ].pcolor (X , Y , Z , cmap = 'PuBu_r' , shading = 'nearest' ,
39+ norm = colors .LogNorm (vmin = Z .min (), vmax = Z .max ()))
40+ ax [1 ]. colorbar ( extend = 'max' , label = 'LogNorm' )
4141
4242# %%
4343# PowerNorm
5353
5454fig , ax = plt .subplots (2 , 1 )
5555
56- pcm = ax [0 ].pcolormesh (X , Y , Z , cmap = 'PuBu_r' , shading = 'nearest' )
57- fig . colorbar ( pcm , ax = ax [0 ], extend = 'max' , label = 'linear scaling' )
56+ ax [0 ].pcolormesh (X , Y , Z , cmap = 'PuBu_r' , shading = 'nearest' )
57+ ax [0 ]. colorbar ( extend = 'max' , label = 'linear scaling' )
5858
59- pcm = ax [1 ].pcolormesh (X , Y , Z , cmap = 'PuBu_r' , shading = 'nearest' ,
60- norm = colors .PowerNorm (gamma = 0.5 ))
61- fig . colorbar ( pcm , ax = ax [1 ], extend = 'max' , label = 'PowerNorm' )
59+ ax [1 ].pcolormesh (X , Y , Z , cmap = 'PuBu_r' , shading = 'nearest' ,
60+ norm = colors .PowerNorm (gamma = 0.5 ))
61+ ax [1 ]. colorbar ( extend = 'max' , label = 'PowerNorm' )
6262
6363# %%
6464# SymLogNorm
7979
8080fig , ax = plt .subplots (2 , 1 )
8181
82- pcm = ax [0 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' ,
83- vmin = - np .max (Z ))
84- fig .colorbar (pcm , ax = ax [0 ], extend = 'both' , label = 'linear scaling' )
82+ ax [0 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' , vmin = - np .max (Z ))
83+ ax [0 ].colorbar (extend = 'both' , label = 'linear scaling' )
8584
86- pcm = ax [1 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' ,
87- norm = colors .SymLogNorm (linthresh = 0.015 ,
88- vmin = - 10.0 , vmax = 10.0 , base = 10 ))
89- fig . colorbar ( pcm , ax = ax [1 ], extend = 'both' , label = 'SymLogNorm' )
85+ ax [1 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' ,
86+ norm = colors .SymLogNorm (linthresh = 0.015 ,
87+ vmin = - 10.0 , vmax = 10.0 , base = 10 ))
88+ ax [1 ]. colorbar ( extend = 'both' , label = 'SymLogNorm' )
9089
9190# %%
9291# Custom Norm
@@ -112,13 +111,12 @@ def __call__(self, value, clip=None):
112111# %%
113112fig , ax = plt .subplots (2 , 1 )
114113
115- pcm = ax [0 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' ,
116- vmin = - np .max (Z ))
117- fig .colorbar (pcm , ax = ax [0 ], extend = 'both' , label = 'linear scaling' )
114+ ax [0 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' , vmin = - np .max (Z ))
115+ ax [0 ].colorbar (extend = 'both' , label = 'linear scaling' )
118116
119- pcm = ax [1 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' ,
120- norm = MidpointNormalize (midpoint = 0 ))
121- fig . colorbar ( pcm , ax = ax [1 ], extend = 'both' , label = 'Custom norm' )
117+ ax [1 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' ,
118+ norm = MidpointNormalize (midpoint = 0 ))
119+ ax [1 ]. colorbar ( extend = 'both' , label = 'Custom norm' )
122120
123121# %%
124122# BoundaryNorm
@@ -129,25 +127,22 @@ def __call__(self, value, clip=None):
129127
130128fig , ax = plt .subplots (3 , 1 , layout = 'constrained' )
131129
132- pcm = ax [0 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' ,
133- vmin = - np .max (Z ))
134- fig .colorbar (pcm , ax = ax [0 ], extend = 'both' , orientation = 'vertical' ,
135- label = 'linear scaling' )
130+ ax [0 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' , vmin = - np .max (Z ))
131+ ax [0 ].colorbar (extend = 'both' , orientation = 'vertical' , label = 'linear scaling' )
136132
137133# Evenly-spaced bounds gives a contour-like effect.
138134bounds = np .linspace (- 2 , 2 , 11 )
139135norm = colors .BoundaryNorm (boundaries = bounds , ncolors = 256 )
140- pcm = ax [1 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' ,
136+ ax [1 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' ,
141137 norm = norm )
142- fig . colorbar ( pcm , ax = ax [1 ], extend = 'both' , orientation = 'vertical' ,
143- label = 'BoundaryNorm\n linspace(-2, 2, 11)' )
138+ ax [1 ]. colorbar ( extend = 'both' , orientation = 'vertical' ,
139+ label = 'BoundaryNorm\n linspace(-2, 2, 11)' )
144140
145141# Unevenly-spaced bounds changes the colormapping.
146142bounds = np .array ([- 1 , - 0.5 , 0 , 2.5 , 5 ])
147143norm = colors .BoundaryNorm (boundaries = bounds , ncolors = 256 )
148- pcm = ax [2 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' ,
149- norm = norm )
150- fig .colorbar (pcm , ax = ax [2 ], extend = 'both' , orientation = 'vertical' ,
151- label = 'BoundaryNorm\n [-1, -0.5, 0, 2.5, 5]' )
144+ ax [2 ].pcolormesh (X , Y , Z , cmap = 'RdBu_r' , shading = 'nearest' , norm = norm )
145+ ax [2 ].colorbar (extend = 'both' , orientation = 'vertical' ,
146+ label = 'BoundaryNorm\n [-1, -0.5, 0, 2.5, 5]' )
152147
153148plt .show ()
0 commit comments