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