14
14
import matplotlib
15
15
from matplotlib import _preprocess_data
16
16
17
+ from matplotlib ._backports import numpy as _backports_np
17
18
import matplotlib .cbook as cbook
18
19
from matplotlib .cbook import (mplDeprecation , STEP_LOOKUP_MAP ,
19
20
iterable , is_string_like ,
@@ -1997,20 +1998,14 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
1997
1998
label = kwargs .pop ('label' , '' )
1998
1999
tick_labels = kwargs .pop ('tick_label' , None )
1999
2000
2000
- def make_iterable (x ):
2001
- if not iterable (x ):
2002
- return [x ]
2003
- else :
2004
- return x
2005
-
2006
2001
# make them safe to take len() of
2007
2002
_left = left
2008
- left = make_iterable (left )
2009
- height = make_iterable (height )
2010
- width = make_iterable (width )
2003
+ left = np . atleast_1d (left )
2004
+ height = np . atleast_1d (height )
2005
+ width = np . atleast_1d (width )
2011
2006
_bottom = bottom
2012
- bottom = make_iterable (bottom )
2013
- linewidth = make_iterable (linewidth )
2007
+ bottom = np . atleast_1d (bottom )
2008
+ linewidth = np . atleast_1d (linewidth )
2014
2009
2015
2010
adjust_ylim = False
2016
2011
adjust_xlim = False
@@ -2025,10 +2020,8 @@ def make_iterable(x):
2025
2020
bottom = [0 ]
2026
2021
2027
2022
nbars = len (left )
2028
- if len (width ) == 1 :
2029
- width *= nbars
2030
- if len (bottom ) == 1 :
2031
- bottom *= nbars
2023
+ width = _backports_np .broadcast_to (width , nbars )
2024
+ bottom = _backports_np .broadcast_to (bottom , nbars )
2032
2025
2033
2026
tick_label_axis = self .xaxis
2034
2027
tick_label_position = left
@@ -2043,18 +2036,16 @@ def make_iterable(x):
2043
2036
left = [0 ]
2044
2037
2045
2038
nbars = len (bottom )
2046
- if len (left ) == 1 :
2047
- left *= nbars
2048
- if len (height ) == 1 :
2049
- height *= nbars
2039
+ left = _backports_np .broadcast_to (left , nbars )
2040
+ height = _backports_np .broadcast_to (height , nbars )
2050
2041
2051
2042
tick_label_axis = self .yaxis
2052
2043
tick_label_position = bottom
2053
2044
else :
2054
2045
raise ValueError ('invalid orientation: %s' % orientation )
2055
2046
2056
2047
if len (linewidth ) < nbars :
2057
- linewidth *= nbars
2048
+ linewidth = np . tile ( linewidth , nbars )
2058
2049
2059
2050
color = list (mcolors .to_rgba_array (color ))
2060
2051
if len (color ) == 0 : # until to_rgba_array is changed
@@ -2181,15 +2172,7 @@ def make_iterable(x):
2181
2172
self .add_container (bar_container )
2182
2173
2183
2174
if tick_labels is not None :
2184
- tick_labels = make_iterable (tick_labels )
2185
- if isinstance (tick_labels , six .string_types ):
2186
- tick_labels = [tick_labels ]
2187
- if len (tick_labels ) == 1 :
2188
- tick_labels *= nbars
2189
- if len (tick_labels ) != nbars :
2190
- raise ValueError ("incompatible sizes: argument 'tick_label' "
2191
- "must be length %d or string" % nbars )
2192
-
2175
+ tick_labels = _backports_np .broadcast_to (tick_labels , nbars )
2193
2176
tick_label_axis .set_ticks (tick_label_position )
2194
2177
tick_label_axis .set_ticklabels (tick_labels )
2195
2178
0 commit comments