@@ -1663,42 +1663,63 @@ def _kind(self) -> Literal["bar", "barh"]:
1663
1663
def orientation (self ) -> PlottingOrientation :
1664
1664
return "vertical"
1665
1665
1666
- def __init__ (self , data , ** kwargs ) -> None :
1666
+ def __init__ (
1667
+ self ,
1668
+ data ,
1669
+ * ,
1670
+ align = "center" ,
1671
+ bottom = 0 ,
1672
+ left = 0 ,
1673
+ width = 0.5 ,
1674
+ position = 0.5 ,
1675
+ log = False ,
1676
+ ** kwargs ,
1677
+ ) -> None :
1667
1678
# we have to treat a series differently than a
1668
1679
# 1-column DataFrame w.r.t. color handling
1669
1680
self ._is_series = isinstance (data , ABCSeries )
1670
- self .bar_width = kwargs . pop ( " width" , 0.5 )
1671
- pos = kwargs . pop ( "position" , 0.5 )
1672
- kwargs . setdefault ( "align" , "center" )
1681
+ self .bar_width = width
1682
+ self . _align = align
1683
+ self . _position = position
1673
1684
self .tick_pos = np .arange (len (data ))
1674
1685
1675
- bottom = kwargs .pop ("bottom" , 0 )
1676
- left = kwargs .pop ("left" , 0 )
1677
1686
if is_list_like (bottom ):
1678
1687
bottom = np .array (bottom )
1679
1688
if is_list_like (left ):
1680
1689
left = np .array (left )
1681
1690
self .bottom = bottom
1682
1691
self .left = left
1683
1692
1684
- self .log = kwargs .pop ("log" , False )
1693
+ self .log = log
1694
+
1685
1695
MPLPlot .__init__ (self , data , ** kwargs )
1686
1696
1697
+ @cache_readonly
1698
+ def ax_pos (self ) -> np .ndarray :
1699
+ return self .tick_pos - self .tickoffset
1700
+
1701
+ @cache_readonly
1702
+ def tickoffset (self ):
1687
1703
if self .stacked or self .subplots :
1688
- self .tickoffset = self .bar_width * pos
1689
- if kwargs ["align" ] == "edge" :
1690
- self .lim_offset = self .bar_width / 2
1691
- else :
1692
- self .lim_offset = 0
1693
- elif kwargs ["align" ] == "edge" :
1704
+ return self .bar_width * self ._position
1705
+ elif self ._align == "edge" :
1694
1706
w = self .bar_width / self .nseries
1695
- self .tickoffset = self .bar_width * (pos - 0.5 ) + w * 0.5
1696
- self .lim_offset = w * 0.5
1707
+ return self .bar_width * (self ._position - 0.5 ) + w * 0.5
1697
1708
else :
1698
- self .tickoffset = self .bar_width * pos
1699
- self .lim_offset = 0
1709
+ return self .bar_width * self ._position
1700
1710
1701
- self .ax_pos = self .tick_pos - self .tickoffset
1711
+ @cache_readonly
1712
+ def lim_offset (self ):
1713
+ if self .stacked or self .subplots :
1714
+ if self ._align == "edge" :
1715
+ return self .bar_width / 2
1716
+ else :
1717
+ return 0
1718
+ elif self ._align == "edge" :
1719
+ w = self .bar_width / self .nseries
1720
+ return w * 0.5
1721
+ else :
1722
+ return 0
1702
1723
1703
1724
# error: Signature of "_plot" incompatible with supertype "MPLPlot"
1704
1725
@classmethod
@@ -1749,6 +1770,7 @@ def _make_plot(self, fig: Figure) -> None:
1749
1770
start = 1
1750
1771
start = start + self ._start_base
1751
1772
1773
+ kwds ["align" ] = self ._align
1752
1774
if self .subplots :
1753
1775
w = self .bar_width / 2
1754
1776
rect = self ._plot (
0 commit comments