@@ -2520,27 +2520,23 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
25202520 height = self ._convert_dx (height , y0 , y , self .convert_yunits )
25212521 if yerr is not None :
25222522 yerr = self ._convert_dx (yerr , y0 , y , self .convert_yunits )
2523+
2524+ # broadcast all args to make them iterable
2525+ x = np .atleast_1d (x )
2526+ args = (x , height , width , y , linewidth , hatch )
2527+ arg_names = ('x' , 'height' , 'width' , 'y' , 'linewidth' , 'hatch' )
25232528 try :
2524- x , height , width , y , linewidth , hatch = np .broadcast_arrays (
2525- # Make args iterable too.
2526- np .atleast_1d (x ), height , width , y , linewidth , hatch
2527- )
2529+ x , height , width , y , linewidth , hatch = np .broadcast_arrays (* args )
25282530 except ValueError as e :
2529- arg_map = {
2530- "arg 0" : "'x'" ,
2531- "arg 1" : "'height'" ,
2532- "arg 2" : "'width'" ,
2533- "arg 3" : "'y'" ,
2534- "arg 4" : "'linewidth'" ,
2535- "arg 5" : "'hatch'"
2536- }
2537- error_message = str (e )
2538- for arg , name in arg_map .items ():
2539- error_message = error_message .replace (arg , name )
2540- if error_message != str (e ):
2541- raise ValueError (error_message ) from e
2542- else :
2543- raise
2531+ non_trivial_inputs = ", " .join (
2532+ f"{ name } { np .shape (arg )} " for arg , name in zip (args , arg_names )
2533+ # only collect args that could contribute to a broadcast error
2534+ if any (dim != 1 for dim in np .shape (arg ))
2535+ )
2536+ raise ValueError (
2537+ f"bar() failed on broadcasting inputs with the following shapes: "
2538+ f"{ non_trivial_inputs } "
2539+ ) from e
25442540
25452541 # Now that units have been converted, set the tick locations.
25462542 if orientation == 'vertical' :
0 commit comments