@@ -2003,14 +2003,11 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
2003
2003
label = kwargs .pop ('label' , '' )
2004
2004
tick_labels = kwargs .pop ('tick_label' , None )
2005
2005
2006
- # make them safe to take len() of
2007
2006
_left = left
2008
- left = np .atleast_1d (left )
2009
- height = np .atleast_1d (height )
2010
- width = np .atleast_1d (width )
2011
2007
_bottom = bottom
2012
- bottom = np .atleast_1d (bottom )
2013
- linewidth = np .atleast_1d (linewidth )
2008
+ left , height , width , bottom = np .broadcast_arrays (
2009
+ # Make args iterable too.
2010
+ np .atleast_1d (left ), height , width , bottom )
2014
2011
2015
2012
adjust_ylim = False
2016
2013
adjust_xlim = False
@@ -2022,11 +2019,7 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
2022
2019
if _bottom is None :
2023
2020
if self .get_yscale () == 'log' :
2024
2021
adjust_ylim = True
2025
- bottom = [0 ]
2026
-
2027
- nbars = len (left )
2028
- width = _backports_np .broadcast_to (width , nbars )
2029
- bottom = _backports_np .broadcast_to (bottom , nbars )
2022
+ bottom = np .zeros_like (bottom )
2030
2023
2031
2024
tick_label_axis = self .xaxis
2032
2025
tick_label_position = left
@@ -2038,54 +2031,23 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
2038
2031
if _left is None :
2039
2032
if self .get_xscale () == 'log' :
2040
2033
adjust_xlim = True
2041
- left = [0 ]
2042
-
2043
- nbars = len (bottom )
2044
- left = _backports_np .broadcast_to (left , nbars )
2045
- height = _backports_np .broadcast_to (height , nbars )
2034
+ left = np .zeros_like (left )
2046
2035
2047
2036
tick_label_axis = self .yaxis
2048
2037
tick_label_position = bottom
2049
2038
else :
2050
2039
raise ValueError ('invalid orientation: %s' % orientation )
2051
2040
2052
- if len (height ) == 1 :
2053
- height *= nbars
2054
- if len (width ) == 1 :
2055
- width *= nbars
2056
- if len (linewidth ) < nbars :
2057
- linewidth = np .tile (linewidth , nbars )
2058
-
2059
- color = list (mcolors .to_rgba_array (color ))
2060
- if len (color ) == 0 : # until to_rgba_array is changed
2061
- color = [[0 , 0 , 0 , 0 ]]
2062
- if len (color ) < nbars :
2063
- color *= nbars
2064
-
2041
+ linewidth = itertools .cycle (np .atleast_1d (linewidth ))
2042
+ color = itertools .chain (itertools .cycle (mcolors .to_rgba_array (color )),
2043
+ # Fallback if color == "none".
2044
+ itertools .repeat ([0 , 0 , 0 , 0 ]))
2065
2045
if edgecolor is None :
2066
- edgecolor = [ None ] * nbars
2046
+ edgecolor = itertools . repeat ( None )
2067
2047
else :
2068
- edgecolor = list (mcolors .to_rgba_array (edgecolor ))
2069
- if len (edgecolor ) == 0 : # until to_rgba_array is changed
2070
- edgecolor = [[0 , 0 , 0 , 0 ]]
2071
- if len (edgecolor ) < nbars :
2072
- edgecolor *= nbars
2073
-
2074
- # input validation
2075
- if len (left ) != nbars :
2076
- raise ValueError ("incompatible sizes: argument 'left' must "
2077
- "be length %d or scalar" % nbars )
2078
- if len (height ) != nbars :
2079
- raise ValueError ("incompatible sizes: argument 'height' "
2080
- "must be length %d or scalar" % nbars )
2081
- if len (width ) != nbars :
2082
- raise ValueError ("incompatible sizes: argument 'width' "
2083
- "must be length %d or scalar" % nbars )
2084
- if len (bottom ) != nbars :
2085
- raise ValueError ("incompatible sizes: argument 'bottom' "
2086
- "must be length %d or scalar" % nbars )
2087
-
2088
- patches = []
2048
+ edgecolor = itertools .chain (mcolors .to_rgba_array (edgecolor ),
2049
+ # Fallback if edgecolor == "none".
2050
+ itertools .repeat ([0 , 0 , 0 , 0 ]))
2089
2051
2090
2052
# lets do some conversions now since some types cannot be
2091
2053
# subtracted uniformly
@@ -2103,13 +2065,14 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
2103
2065
2104
2066
if align == 'center' :
2105
2067
if orientation == 'vertical' :
2106
- left = [ l - w / 2. for l , w in zip ( left , width )]
2068
+ left = left - width / 2
2107
2069
elif orientation == 'horizontal' :
2108
- bottom = [ b - h / 2. for b , h in zip ( bottom , height )]
2070
+ bottom = bottom - height / 2
2109
2071
2110
2072
elif align != 'edge' :
2111
2073
raise ValueError ('invalid alignment: %s' % align )
2112
2074
2075
+ patches = []
2113
2076
args = zip (left , bottom , width , height , color , edgecolor , linewidth )
2114
2077
for l , b , w , h , c , e , lw in args :
2115
2078
r = mpatches .Rectangle (
@@ -2174,7 +2137,7 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
2174
2137
self .add_container (bar_container )
2175
2138
2176
2139
if tick_labels is not None :
2177
- tick_labels = _backports_np .broadcast_to (tick_labels , nbars )
2140
+ tick_labels = _backports_np .broadcast_to (tick_labels , len ( patches ) )
2178
2141
tick_label_axis .set_ticks (tick_label_position )
2179
2142
tick_label_axis .set_ticklabels (tick_labels )
2180
2143
0 commit comments