@@ -1685,6 +1685,33 @@ def __init__(self, *args, **kwargs):
1685
1685
self .set_params (** self .default_params )
1686
1686
self .set_params (** kwargs )
1687
1687
1688
+ @staticmethod
1689
+ def _validate_steps (steps ):
1690
+ if not np .iterable (steps ):
1691
+ raise ValueError ('steps argument must be a sequence of numbers '
1692
+ 'from 1 to 10' )
1693
+ steps = np .asarray (steps )
1694
+ if np .any (np .diff (steps ) <= 0 ):
1695
+ raise ValueError ('steps argument must be uniformly increasing' )
1696
+ if np .any ((steps > 10 ) | (steps < 1 )):
1697
+ warnings .warn ('Steps argument should be a sequence of numbers\n '
1698
+ 'increasing from 1 to 10, inclusive. Behavior with\n '
1699
+ 'values outside this range is undefined, and will\n '
1700
+ 'raise a ValueError in future versions of mpl.' )
1701
+ if steps [0 ] != 1 :
1702
+ steps = np .hstack ((1 , steps ))
1703
+ if steps [- 1 ] != 10 :
1704
+ steps = np .hstack ((steps , 10 ))
1705
+ return steps
1706
+
1707
+ @staticmethod
1708
+ def _staircase (steps ):
1709
+ # Make an extended staircase within which the needed
1710
+ # step will be found. This is probably much larger
1711
+ # than necessary.
1712
+ flights = (0.1 * steps [:- 1 ], steps , 10 * steps [1 ])
1713
+ return np .hstack (flights )
1714
+
1688
1715
def set_params (self , ** kwargs ):
1689
1716
"""Set parameters within this locator."""
1690
1717
if 'nbins' in kwargs :
@@ -1706,23 +1733,16 @@ def set_params(self, **kwargs):
1706
1733
if 'steps' in kwargs :
1707
1734
steps = kwargs ['steps' ]
1708
1735
if steps is None :
1709
- self ._steps = [1 , 1.5 , 2 , 2.5 , 3 , 4 , 5 , 6 , 8 , 10 ]
1736
+ self ._steps = np . array ( [1 , 1.5 , 2 , 2.5 , 3 , 4 , 5 , 6 , 8 , 10 ])
1710
1737
else :
1711
- if int (steps [- 1 ]) != 10 :
1712
- steps = list (steps )
1713
- steps .append (10 )
1714
- self ._steps = steps
1715
- # Make an extended staircase within which the needed
1716
- # step will be found. This is probably much larger
1717
- # than necessary.
1718
- flights = (0.1 * np .array (self ._steps [:- 1 ]),
1719
- self ._steps ,
1720
- [10 * self ._steps [1 ]])
1721
- self ._extended_steps = np .hstack (flights )
1738
+ self ._steps = self ._validate_steps (steps )
1739
+ self ._extended_steps = self ._staircase (self ._steps )
1722
1740
if 'integer' in kwargs :
1723
1741
self ._integer = kwargs ['integer' ]
1724
1742
if self ._integer :
1725
- self ._steps = [n for n in self ._steps if _divmod (n , 1 )[1 ] < 0.001 ]
1743
+ self ._steps = np .array ([n for n in self ._steps
1744
+ if _divmod (n , 1 )[1 ] < 0.001 ])
1745
+ self ._extended_steps = self ._staircase (self ._steps )
1726
1746
if 'min_n_ticks' in kwargs :
1727
1747
self ._min_n_ticks = max (1 , kwargs ['min_n_ticks' ])
1728
1748
0 commit comments