@@ -848,7 +848,12 @@ def test_animated_with_canvas_change(fig_test, fig_ref):
848848class TestSubplotMosaic :
849849 @check_figures_equal (extensions = ["png" ])
850850 @pytest .mark .parametrize (
851- "x" , [[["A" , "A" , "B" ], ["C" , "D" , "B" ]], [[1 , 1 , 2 ], [3 , 4 , 2 ]]]
851+ "x" , [
852+ [["A" , "A" , "B" ], ["C" , "D" , "B" ]],
853+ [[1 , 1 , 2 ], [3 , 4 , 2 ]],
854+ (("A" , "A" , "B" ), ("C" , "D" , "B" )),
855+ ((1 , 1 , 2 ), (3 , 4 , 2 ))
856+ ]
852857 )
853858 def test_basic (self , fig_test , fig_ref , x ):
854859 grid_axes = fig_test .subplot_mosaic (x )
@@ -998,6 +1003,10 @@ def test_fail_list_of_str(self):
9981003 plt .subplot_mosaic (['foo' , 'bar' ])
9991004 with pytest .raises (ValueError , match = 'must be 2D' ):
10001005 plt .subplot_mosaic (['foo' ])
1006+ with pytest .raises (ValueError , match = 'must be 2D' ):
1007+ plt .subplot_mosaic ([['foo' , ('bar' ,)]])
1008+ with pytest .raises (ValueError , match = 'must be 2D' ):
1009+ plt .subplot_mosaic ([['a' , 'b' ], [('a' , 'b' ), 'c' ]])
10011010
10021011 @check_figures_equal (extensions = ["png" ])
10031012 @pytest .mark .parametrize ("subplot_kw" , [{}, {"projection" : "polar" }, None ])
@@ -1011,8 +1020,26 @@ def test_subplot_kw(self, fig_test, fig_ref, subplot_kw):
10111020
10121021 axB = fig_ref .add_subplot (gs [0 , 1 ], ** subplot_kw )
10131022
1023+ @check_figures_equal (extensions = ["png" ])
1024+ @pytest .mark .parametrize ("multi_value" , ['BC' , tuple ('BC' )])
1025+ def test_per_subplot_kw (self , fig_test , fig_ref , multi_value ):
1026+ x = 'AB;CD'
1027+ grid_axes = fig_test .subplot_mosaic (
1028+ x ,
1029+ subplot_kw = {'facecolor' : 'red' },
1030+ per_subplot_kw = {
1031+ 'D' : {'facecolor' : 'blue' },
1032+ multi_value : {'facecolor' : 'green' },
1033+ }
1034+ )
1035+
1036+ gs = fig_ref .add_gridspec (2 , 2 )
1037+ for color , spec in zip (['red' , 'green' , 'green' , 'blue' ], gs ):
1038+ fig_ref .add_subplot (spec , facecolor = color )
1039+
10141040 def test_string_parser (self ):
10151041 normalize = Figure ._normalize_grid_string
1042+
10161043 assert normalize ('ABC' ) == [['A' , 'B' , 'C' ]]
10171044 assert normalize ('AB;CC' ) == [['A' , 'B' ], ['C' , 'C' ]]
10181045 assert normalize ('AB;CC;DE' ) == [['A' , 'B' ], ['C' , 'C' ], ['D' , 'E' ]]
@@ -1029,6 +1056,25 @@ def test_string_parser(self):
10291056 DE
10301057 """ ) == [['A' , 'B' ], ['C' , 'C' ], ['D' , 'E' ]]
10311058
1059+ def test_per_subplot_kw_expander (self ):
1060+ normalize = Figure ._norm_per_subplot_kw
1061+ assert normalize ({"A" : {}, "B" : {}}) == {"A" : {}, "B" : {}}
1062+ assert normalize ({("A" , "B" ): {}}) == {"A" : {}, "B" : {}}
1063+ with pytest .raises (
1064+ ValueError , match = f'The key { "B" !r} appears multiple times'
1065+ ):
1066+ normalize ({("A" , "B" ): {}, "B" : {}})
1067+ with pytest .raises (
1068+ ValueError , match = f'The key { "B" !r} appears multiple times'
1069+ ):
1070+ normalize ({"B" : {}, ("A" , "B" ): {}})
1071+
1072+ def test_extra_per_subplot_kw (self ):
1073+ with pytest .raises (
1074+ ValueError , match = f'The keys { set ("B" )!r} are in'
1075+ ):
1076+ Figure ().subplot_mosaic ("A" , per_subplot_kw = {"B" : {}})
1077+
10321078 @check_figures_equal (extensions = ["png" ])
10331079 @pytest .mark .parametrize ("str_pattern" ,
10341080 ["AAA\n BBB" , "\n AAA\n BBB\n " , "ABC\n DEF" ]
0 commit comments