@@ -836,6 +836,8 @@ def cla(self):
836
836
837
837
self ._autoscaleXon = True
838
838
self ._autoscaleYon = True
839
+ self ._xmargin = 0
840
+ self ._ymargin = 0
839
841
self ._update_transScale () # needed?
840
842
841
843
self ._get_lines = _process_plot_var_args (self )
@@ -1605,6 +1607,83 @@ def set_autoscaley_on(self, b):
1605
1607
"""
1606
1608
self ._autoscaleYon = b
1607
1609
1610
+ def set_xmargin (self , m ):
1611
+ """
1612
+ Set padding of X data limits prior to autoscaling.
1613
+
1614
+ *m* times the data interval will be added to each
1615
+ end of that interval before it is used in autoscaling.
1616
+
1617
+ accepts: float in range 0 to 1
1618
+ """
1619
+ if m < 0 or m > 1 :
1620
+ raise ValueError ("margin must be in range 0 to 1" )
1621
+ self ._xmargin = m
1622
+
1623
+ def set_ymargin (self , m ):
1624
+ """
1625
+ Set padding of Y data limits prior to autoscaling.
1626
+
1627
+ *m* times the data interval will be added to each
1628
+ end of that interval before it is used in autoscaling.
1629
+
1630
+ accepts: float in range 0 to 1
1631
+ """
1632
+ if m < 0 or m > 1 :
1633
+ raise ValueError ("margin must be in range 0 to 1" )
1634
+ self ._ymargin = m
1635
+
1636
+
1637
+ def margins (self , * args , ** kw ):
1638
+ """
1639
+ Convenience method to set or retrieve autoscaling margins.
1640
+
1641
+ signatures::
1642
+
1643
+ margins()
1644
+
1645
+ returns xmargin, ymargin
1646
+
1647
+ ::
1648
+
1649
+ margins(margin, tight=True)
1650
+
1651
+ margins(xmargin, ymargin, tight=True)
1652
+
1653
+ margins(x=xmargin, y=ymargin, tight=True)
1654
+
1655
+ All three forms above set the xmargin and ymargin parameters.
1656
+ All keyword parameters are optional. A single argument
1657
+ specifies both xmargin and ymargin. The *tight* parameter
1658
+ is passed to :meth:`autoscale_view`, which is executed after
1659
+ a margin is changed.
1660
+
1661
+ Specifying any margin changes only the autoscaling; for example,
1662
+ if *xmargin* is not zero, then *xmargin* times the X data
1663
+ interval will be added to each end of that interval before
1664
+ it is used in autoscaling.
1665
+
1666
+ """
1667
+ if not args and not kw :
1668
+ return self ._ymargin , self ._ymargin
1669
+
1670
+ tight = kw .pop ('tight' , False )
1671
+ mx = kw .pop ('x' , None )
1672
+ my = kw .pop ('y' , None )
1673
+ if len (args ) == 1 :
1674
+ mx = my = args [0 ]
1675
+ elif len (args ) == 2 :
1676
+ mx , my = args
1677
+ else :
1678
+ raise ValueError ("more than two arguments were supplied" )
1679
+ if mx is not None :
1680
+ self .set_xmargin (mx )
1681
+ if my is not None :
1682
+ self .set_ymargin (my )
1683
+
1684
+ self .autoscale_view (tight = tight , scalex = bool (mx ), scaley = bool (my ))
1685
+
1686
+
1608
1687
def set_rasterization_zorder (self , z ):
1609
1688
"""
1610
1689
Set zorder value below which artists will be rasterized
@@ -1631,11 +1710,21 @@ def autoscale_view(self, tight=False, scalex=True, scaley=True):
1631
1710
dl = [ax .dataLim for ax in xshared ]
1632
1711
bb = mtransforms .BboxBase .union (dl )
1633
1712
x0 , x1 = bb .intervalx
1713
+ if self ._xmargin > 0 :
1714
+ delta = (x1 - x0 ) * self ._xmargin
1715
+ x0 -= delta
1716
+ x1 += delta
1717
+
1634
1718
if scaley and self ._autoscaleYon :
1635
1719
yshared = self ._shared_y_axes .get_siblings (self )
1636
1720
dl = [ax .dataLim for ax in yshared ]
1637
1721
bb = mtransforms .BboxBase .union (dl )
1638
1722
y0 , y1 = bb .intervaly
1723
+ if self ._ymargin > 0 :
1724
+ delta = (y1 - y0 ) * self ._ymargin
1725
+ y0 -= delta
1726
+ y1 += delta
1727
+
1639
1728
if (tight or (len (self .images )> 0 and
1640
1729
len (self .lines )== 0 and
1641
1730
len (self .patches )== 0 )):
@@ -1958,7 +2047,7 @@ def locator_params(self, axis='both', tight=False, **kwargs):
1958
2047
of ticks and use tight bounds when plotting small
1959
2048
subplots, for example::
1960
2049
1961
- ax.set_locator_params (tight=True, nbins=4)
2050
+ ax.locator_params (tight=True, nbins=4)
1962
2051
1963
2052
Because the locator is involved in autoscaling,
1964
2053
:meth:`autoscale_view` is called automatically after
0 commit comments