@@ -931,28 +931,51 @@ def test_proportional_colorbars():
931
931
fig .colorbar (CS3 , spacing = spacings [j ], ax = axs [i , j ])
932
932
933
933
934
- @pytest .mark .parametrize ("extend, coloroffset, res" , [
935
- ('both' , 1 , [np .array ([[0. , 0. ], [0. , 1. ]]),
936
- np .array ([[1. , 0. ], [1. , 1. ]]),
937
- np .array ([[2. , 0. ], [2. , 1. ]])]),
938
- ('min' , 0 , [np .array ([[0. , 0. ], [0. , 1. ]]),
939
- np .array ([[1. , 0. ], [1. , 1. ]])]),
940
- ('max' , 0 , [np .array ([[1. , 0. ], [1. , 1. ]]),
941
- np .array ([[2. , 0. ], [2. , 1. ]])]),
942
- ('neither' , - 1 , [np .array ([[1. , 0. ], [1. , 1. ]])])
943
- ])
944
- def test_colorbar_extend_drawedges (extend , coloroffset , res ):
945
- cmap = plt .get_cmap ("viridis" )
946
- bounds = np .arange (3 )
947
- nb_colors = len (bounds ) + coloroffset
948
- colors = cmap (np .linspace (100 , 255 , nb_colors ).astype (int ))
949
- cmap , norm = mcolors .from_levels_and_colors (bounds , colors , extend = extend )
950
-
951
- plt .figure (figsize = (5 , 1 ))
952
- ax = plt .subplot (111 )
953
- cbar = Colorbar (ax , cmap = cmap , norm = norm , orientation = 'horizontal' ,
954
- drawedges = True )
955
- assert np .all (np .equal (cbar .dividers .get_segments (), res ))
934
+ @image_comparison (['extend_drawedges.png' ], remove_text = True , style = 'mpl20' )
935
+ def test_colorbar_extend_drawedges ():
936
+ params = [
937
+ ('both' , 1 , [[[1.1 , 0 ], [1.1 , 1 ]],
938
+ [[2 , 0 ], [2 , 1 ]],
939
+ [[2.9 , 0 ], [2.9 , 1 ]]]),
940
+ ('min' , 0 , [[[1.1 , 0 ], [1.1 , 1 ]],
941
+ [[2 , 0 ], [2 , 1 ]]]),
942
+ ('max' , 0 , [[[2 , 0 ], [2 , 1 ]],
943
+ [[2.9 , 0 ], [2.9 , 1 ]]]),
944
+ ('neither' , - 1 , [[[2 , 0 ], [2 , 1 ]]]),
945
+ ]
946
+
947
+ plt .rcParams ['axes.linewidth' ] = 2
948
+
949
+ fig = plt .figure (figsize = (10 , 4 ))
950
+ subfigs = fig .subfigures (1 , 2 )
951
+
952
+ for orientation , subfig in zip (['horizontal' , 'vertical' ], subfigs ):
953
+ if orientation == 'horizontal' :
954
+ axs = subfig .subplots (4 , 1 )
955
+ else :
956
+ axs = subfig .subplots (1 , 4 )
957
+ fig .subplots_adjust (left = 0.05 , bottom = 0.05 , right = 0.95 , top = 0.95 )
958
+
959
+ for ax , (extend , coloroffset , res ) in zip (axs , params ):
960
+ cmap = plt .get_cmap ("viridis" )
961
+ bounds = np .arange (5 )
962
+ nb_colors = len (bounds ) + coloroffset
963
+ colors = cmap (np .linspace (100 , 255 , nb_colors ).astype (int ))
964
+ cmap , norm = mcolors .from_levels_and_colors (bounds , colors ,
965
+ extend = extend )
966
+
967
+ cbar = Colorbar (ax , cmap = cmap , norm = norm , orientation = orientation ,
968
+ drawedges = True )
969
+ # Set limits such that only two colours are visible, and the
970
+ # dividers would be outside the Axes, to ensure that a) they are
971
+ # not drawn outside, and b) a divider still appears between the
972
+ # main colour and the extension.
973
+ if orientation == 'horizontal' :
974
+ ax .set_xlim (1.1 , 2.9 )
975
+ else :
976
+ ax .set_ylim (1.1 , 2.9 )
977
+ res = np .array (res )[:, :, [1 , 0 ]]
978
+ np .testing .assert_array_equal (cbar .dividers .get_segments (), res )
956
979
957
980
958
981
def test_negative_boundarynorm ():
0 commit comments