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