@@ -827,3 +827,30 @@ def test_aspects():
827827 np .testing .assert_almost_equal (
828828 cb [1 ][0 ].ax .get_position (original = False ).height * 2 ,
829829 cb [1 ][2 ].ax .get_position (original = False ).height , decimal = 2 )
830+
831+
832+ @image_comparison (['proportional_colorbars.png' ], remove_text = True ,
833+ style = 'mpl20' )
834+ def test_proportional_colorbars ():
835+
836+ x = y = np .arange (- 3.0 , 3.01 , 0.025 )
837+ X , Y = np .meshgrid (x , y )
838+ Z1 = np .exp (- X ** 2 - Y ** 2 )
839+ Z2 = np .exp (- (X - 1 )** 2 - (Y - 1 )** 2 )
840+ Z = (Z1 - Z2 ) * 2
841+
842+ levels = [- 1.25 , - 0.5 , - 0.125 , 0.125 , 0.5 , 1.25 ]
843+ cmap = mcolors .ListedColormap (
844+ ['0.3' , '0.5' , 'white' , 'lightblue' , 'steelblue' ])
845+ cmap .set_under ('darkred' )
846+ cmap .set_over ('crimson' )
847+ norm = mcolors .BoundaryNorm (levels , cmap .N )
848+
849+ extends = ['neither' , 'both' ]
850+ spacings = ['uniform' , 'proportional' ]
851+ fig , axs = plt .subplots (2 , 2 )
852+ for i in range (2 ):
853+ for j in range (2 ):
854+ CS3 = axs [i , j ].contourf (X , Y , Z , levels , cmap = cmap , norm = norm ,
855+ extend = extends [i ])
856+ fig .colorbar (CS3 , spacing = spacings [j ], ax = axs [i , j ])
0 commit comments