@@ -1802,7 +1802,8 @@ def step(self, x, y, *args, **kwargs):
1802
1802
return self .plot (x , y , * args , ** kwargs )
1803
1803
1804
1804
@docstring .dedent_interpd
1805
- def bar (self , left , height , width = 0.8 , bottom = None , ** kwargs ):
1805
+ def bar (self , left , height , width = 0.8 , bottom = None , tick_label = None ,
1806
+ ** kwargs ):
1806
1807
"""
1807
1808
Make a bar plot.
1808
1809
@@ -1813,8 +1814,8 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
1813
1814
1814
1815
Parameters
1815
1816
----------
1816
- left : sequence of scalars or strings
1817
- the x coordinates or labels of the left sides of the bars
1817
+ left : sequence of scalars
1818
+ the x coordinates of the left sides of the bars
1818
1819
1819
1820
height : sequence of scalars
1820
1821
the heights of the bars
@@ -1823,7 +1824,10 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
1823
1824
the width(s) of the bars
1824
1825
1825
1826
bottom : scalar or array-like, optional, default: None
1826
- the y coordinate(s) or labels of the bars
1827
+ the y coordinate(s) of the bars
1828
+
1829
+ tick_label : string or array-like, optional, default: None
1830
+ the tick labels of the bars
1827
1831
1828
1832
color : scalar or array-like, optional
1829
1833
the colors of the bar faces
@@ -1926,6 +1930,8 @@ def make_iterable(x):
1926
1930
width = make_iterable (width )
1927
1931
_bottom = bottom
1928
1932
bottom = make_iterable (bottom )
1933
+ _tick_label = tick_label
1934
+ tick_label = make_iterable (tick_label )
1929
1935
linewidth = make_iterable (linewidth )
1930
1936
1931
1937
adjust_ylim = False
@@ -1945,14 +1951,8 @@ def make_iterable(x):
1945
1951
width *= nbars
1946
1952
if len (bottom ) == 1 :
1947
1953
bottom *= nbars
1948
- if nbars and cbook .is_sequence_of_strings (left ):
1949
- ticks_loc = [i + w / 2 for i , w in enumerate (width )]
1950
- self .xaxis .set_ticks (ticks_loc )
1951
- self .xaxis .set_ticklabels (left )
1952
- left = np .arange (nbars )
1953
- if nbars and cbook .is_sequence_of_strings (bottom ):
1954
- raise ValueError ('bottom must be scalar or sequence of scalar '
1955
- 'for vertical bar' )
1954
+
1955
+ tick_label_position = left
1956
1956
elif orientation == 'horizontal' :
1957
1957
self ._process_unit_info (xdata = width , ydata = bottom , kwargs = kwargs )
1958
1958
if log :
@@ -1968,17 +1968,13 @@ def make_iterable(x):
1968
1968
left *= nbars
1969
1969
if len (height ) == 1 :
1970
1970
height *= nbars
1971
- if nbars and cbook .is_sequence_of_strings (bottom ):
1972
- ticks_loc = [i + h / 2 for i , h in enumerate (height )]
1973
- self .yaxis .set_ticks (ticks_loc )
1974
- self .yaxis .set_ticklabels (bottom )
1975
- bottom = np .arange (nbars )
1976
- if nbars and cbook .is_sequence_of_strings (left ):
1977
- raise ValueError ('left must be scalar or sequence of scalar '
1978
- 'for horizontal bar' )
1971
+
1972
+ tick_label_position = bottom
1979
1973
else :
1980
1974
raise ValueError ('invalid orientation: %s' % orientation )
1981
1975
1976
+ if len (tick_label ) == 1 :
1977
+ tick_label *= nbars
1982
1978
if len (linewidth ) < nbars :
1983
1979
linewidth *= nbars
1984
1980
@@ -2013,6 +2009,9 @@ def make_iterable(x):
2013
2009
if len (bottom ) != nbars :
2014
2010
raise ValueError ("incompatible sizes: argument 'bottom' "
2015
2011
"must be length %d or scalar" % nbars )
2012
+ if len (tick_label ) != nbars :
2013
+ raise ValueError ("incompatible sizes: argument 'tick_label' "
2014
+ "must be length %d or string" % nbars )
2016
2015
2017
2016
patches = []
2018
2017
@@ -2108,6 +2107,11 @@ def make_iterable(x):
2108
2107
bar_container = BarContainer (patches , errorbar , label = label )
2109
2108
self .add_container (bar_container )
2110
2109
2110
+ if _tick_label is not None :
2111
+ axis = self .xaxis if orientation == 'vertical' else self .yaxis
2112
+ axis .set_ticks (tick_label_position )
2113
+ axis .set_ticklabels (tick_label )
2114
+
2111
2115
return bar_container
2112
2116
2113
2117
@docstring .dedent_interpd
@@ -2126,7 +2130,7 @@ def barh(self, bottom, width, height=0.8, left=None, **kwargs):
2126
2130
Parameters
2127
2131
----------
2128
2132
bottom : scalar or array-like
2129
- the y coordinate(s) or labels of the bars
2133
+ the y coordinate(s) of the bars
2130
2134
2131
2135
width : scalar or array-like
2132
2136
the width(s) of the bars
@@ -2153,6 +2157,9 @@ def barh(self, bottom, width, height=0.8, left=None, **kwargs):
2153
2157
width of bar edge(s). If None, use default
2154
2158
linewidth; If 0, don't draw edges.
2155
2159
2160
+ tick_label : string or array-like, optional, default: None
2161
+ the tick labels of the bars
2162
+
2156
2163
xerr : scalar or array-like, optional, default: None
2157
2164
if not None, will be used to generate errorbar(s) on the bar chart
2158
2165
0 commit comments