@@ -4603,56 +4603,62 @@ def test_hist_stacked_bar():
46034603 ax .legend (loc = 'upper right' , bbox_to_anchor = (1.0 , 1.0 ), ncols = 1 )
46044604
46054605
4606+ @pytest .mark .parametrize ('kwargs' , ({'facecolor' : ["b" , "g" , "r" ]},
4607+ {'edgecolor' : ["b" , "g" , "r" ]},
4608+ {'hatch' : ["/" , "\\ " , "." ]},
4609+ {'linestyle' : ["-" , "--" , ":" ]},
4610+ {'linewidth' : [1 , 1.5 , 2 ]},
4611+ {'color' : ["b" , "g" , "r" ]}))
46064612@check_figures_equal (extensions = ["png" ])
4607- def test_hist_vectorized_params (fig_test , fig_ref ):
4613+ def test_hist_vectorized_params (fig_test , fig_ref , kwargs ):
46084614 np .random .seed (19680801 )
46094615 x = [np .random .randn (n ) for n in [2000 , 5000 , 10000 ]]
46104616
4611- facecolor = [ "b" , "g" , "r" ]
4612- edgecolor = [ "b" , "g" , "r" ]
4613- hatch = [ "/" , " \\ " , "." ]
4614- linestyle = [ "- " , "--" , ":" ]
4615- linewidth = [ 1 , 1.5 , 2 ]
4616- colors = [ "b" , "g" , "r" ]
4617- (( axt1 , axt2 , axt3 ), ( axt4 , axt5 , axt6 )) = fig_test . subplots ( 2 , 3 )
4618- (( axr1 , axr2 , axr3 ) , (axr4 , axr5 , axr6 )) = fig_ref . subplots ( 2 , 3 )
4619-
4620- _ , bins , _ = axt1 . hist ( x , bins = 10 , histtype = "stepfilled" , facecolor = facecolor )
4621-
4622- for i , ( xi , fc ) in enumerate ( zip ( x , facecolor )):
4623- axr1 . hist ( xi , bins = bins , histtype = "stepfilled" , facecolor = fc ,
4624- zorder = ( len ( x ) - i ) / 2 )
4625-
4626- _ , bins , _ = axt2 . hist ( x , bins = 10 , histtype = " step" , edgecolor = edgecolor )
4627-
4628- for i , ( xi , ec ) in enumerate ( zip ( x , edgecolor )):
4629- axr2 . hist ( xi , bins = bins , histtype = "step" , edgecolor = ec , zorder = ( len ( x ) - i ) / 2 )
4630-
4631- _ , bins , _ = axt3 . hist ( x , bins = 10 , histtype = "stepfilled" , hatch = hatch ,
4632- facecolor = facecolor )
4633-
4634- for i , ( xi , fc , ht ) in enumerate ( zip ( x , facecolor , hatch )):
4635- axr3 . hist ( xi , bins = bins , histtype = "stepfilled" , hatch = ht , facecolor = fc ,
4636- zorder = ( len ( x ) - i ) / 2 )
4637-
4638- _ , bins , _ = axt4 . hist ( x , bins = 10 , histtype = " step" , linestyle = linestyle ,
4639- edgecolor = edgecolor )
4640-
4641- for i , ( xi , ec , ls ) in enumerate ( zip ( x , edgecolor , linestyle )):
4642- axr4 . hist ( xi , bins = bins , histtype = "step" , linestyle = ls , edgecolor = ec ,
4643- zorder = ( len ( x ) - i ) / 2 )
4644-
4645- _ , bins , _ = axt5 . hist ( x , bins = 10 , histtype = "step" , linewidth = linewidth ,
4646- edgecolor = edgecolor )
4647-
4648- for i , ( xi , ec , lw ) in enumerate ( zip ( x , edgecolor , linewidth ) ):
4649- axr5 . hist (xi , bins = bins , histtype = "step" , linewidth = lw , edgecolor = ec ,
4650- zorder = ( len ( x ) - i ) / 2 )
4651-
4652- _ , bins , _ = axt6 . hist ( x , bins = 10 , histtype = "stepfilled" , color = colors )
4653-
4654- for i , ( xi , c ) in enumerate ( zip ( x , colors )):
4655- axr6 . hist ( xi , bins = bins , histtype = "stepfilled" , color = c , zorder = ( len ( x ) - i ) / 2 )
4617+ ( axt1 , axt2 ) = fig_test . subplots ( 2 )
4618+ ( axr1 , axr2 ) = fig_ref . subplots ( 2 )
4619+
4620+ for histtype , axt , axr in [( "stepfilled " , axt1 , axr1 ), ( "step" , axt2 , axr2 )]:
4621+ _ , bins , _ = axt . hist ( x , bins = 10 , histtype = histtype , ** kwargs )
4622+
4623+ kw , values = next ( iter ( kwargs . items ()) )
4624+ for i , (xi , value ) in enumerate ( zip ( x , values )):
4625+ axr . hist ( xi , bins = bins , histtype = histtype , ** { kw : value },
4626+ zorder = ( len ( x ) - i ) / 2 )
4627+
4628+
4629+ @ pytest . mark . parametrize ( 'kwargs, patch_face, patch_edge' ,
4630+ [({ 'histtype' : 'stepfilled' , 'color' : 'r' ,
4631+ 'facecolor' : 'y' , 'edgecolor' : 'g' }, 'y' , 'g' ),
4632+ ({ ' histtype' : ' step' , 'color' : 'r' ,
4633+ 'facecolor' : 'y' , 'edgecolor' : 'g' }, ( 'y' , 0 ), 'g' ),
4634+ ({ 'histtype' : 'stepfilled' , 'color' : 'r' ,
4635+ ' edgecolor' : 'g' }, 'r' , 'g' ),
4636+ ({ 'histtype' : 'step' , 'color' : 'r' ,
4637+ 'edgecolor' : 'g' }, ( 'r' , 0 ), 'g' ) ,
4638+ ({ 'histtype' : 'stepfilled' , 'color' : 'r' ,
4639+ 'facecolor' : 'y' }, 'y' , 'k' ),
4640+ ({ 'histtype' : 'step' , 'color' : 'r' ,
4641+ 'facecolor' : 'y' }, ( 'y' , 0 ), 'r' ) ,
4642+ ({ 'histtype' : 'stepfilled' ,
4643+ 'facecolor' : 'y' , 'edgecolor' : 'g' }, 'y' , 'g' ),
4644+ ({ ' histtype' : ' step' , 'facecolor' : 'y' ,
4645+ ' edgecolor' : 'g' }, ( 'y' , 0 ), 'g' ),
4646+ ({ 'histtype' : 'stepfilled' , 'color' : 'r' }, 'r' , 'k' ),
4647+ ({ 'histtype' : 'step' , 'color' : 'r' }, ( 'r' , 0 ), 'r' ),
4648+ ({ 'histtype' : 'stepfilled' , 'facecolor' : 'y' }, 'y' , 'k' ) ,
4649+ ({ 'histtype' : 'step' , 'facecolor' : 'y' }, ( 'y' , 0 ), 'C0' ),
4650+ ({ 'histtype' : 'stepfilled' , 'edgecolor' : 'g' }, 'C0' , 'g' ),
4651+ ({ 'histtype' : 'step' , 'edgecolor' : 'g' }, ( 'C0' , 0 ), 'g' ) ,
4652+ ({ 'histtype' : 'stepfilled' }, 'C0' , 'k' ),
4653+ ({ 'histtype' : 'step' }, ( 'C0' , 0 ), 'C0' )])
4654+ def test_hist_color_semantics ( kwargs , patch_face , patch_edge ):
4655+ _ , _ , patches = plt . figure (). subplots (). hist ([ 1 , 2 , 3 ], ** kwargs )
4656+ # 'C0'(blue) stands for the first color of the default color cycle
4657+ # as well as the patch.facecolor rcParam
4658+ # When the expected edgecolor is 'k'(black), it corresponds to the
4659+ # patch.edgecolor rcParam
4660+ assert all ( mcolors . same_color ([ p . get_facecolor (), p . get_edgecolor ()],
4661+ [ patch_face , patch_edge ]) for p in patches )
46564662
46574663
46584664def test_hist_barstacked_bottom_unchanged ():
0 commit comments