@@ -819,12 +819,31 @@ class Locator(TickHelper):
819
819
# This parameter is set to cause locators to raise an error if too
820
820
# many ticks are generated
821
821
MAXTICKS = 1000
822
- def __call__ (self ):
823
- 'Return the locations of the ticks'
822
+
823
+ def tick_values (self , vmin , vmax ):
824
+ """
825
+ Return the values of the located ticks given **vmin** and **vmax**.
826
+
827
+ .. note::
828
+ To get tick locations with the vmin and vmax values defined
829
+ automatically for the associated :attr:`axis` simply call
830
+ the Locator instance::
831
+
832
+ >>> print(type(loc))
833
+ <type 'Locator'>
834
+ >>> print(loc())
835
+ [1, 2, 3, 4]
836
+
837
+ """
824
838
raise NotImplementedError ('Derived must override' )
825
839
840
+ def __call__ (self ):
841
+ """Return the locations of the ticks"""
842
+ vmin , vmax = self .axis .get_view_interval ()
843
+ self .tick_values (vmin , vmax )
844
+
826
845
def raise_if_exceeds (self , locs ):
827
- ' raise a RuntimeError if Locator attempts to create more than MAXTICKS locs'
846
+ """ raise a RuntimeError if Locator attempts to create more than MAXTICKS locs"""
828
847
if len (locs )>= self .MAXTICKS :
829
848
msg = ('Locator attempting to generate %d ticks from %s to %s: ' +
830
849
'exceeds Locator.MAXTICKS' ) % (len (locs ), locs [0 ], locs [- 1 ])
@@ -841,11 +860,11 @@ def view_limits(self, vmin, vmax):
841
860
return mtransforms .nonsingular (vmin , vmax )
842
861
843
862
def autoscale (self ):
844
- ' autoscale the view limits'
863
+ """ autoscale the view limits"""
845
864
return self .view_limits (* self .axis .get_view_interval ())
846
865
847
866
def pan (self , numsteps ):
848
- ' Pan numticks (can be positive or negative)'
867
+ """ Pan numticks (can be positive or negative)"""
849
868
ticks = self ()
850
869
numticks = len (ticks )
851
870
@@ -872,7 +891,7 @@ def zoom(self, direction):
872
891
self .axis .set_view_interval (vmin + step , vmax - step , ignore = True )
873
892
874
893
def refresh (self ):
875
- ' refresh internal information based on current lim'
894
+ """ refresh internal information based on current lim"""
876
895
pass
877
896
878
897
@@ -889,8 +908,11 @@ def __init__(self, base, offset):
889
908
self .offset = offset
890
909
891
910
def __call__ (self ):
892
- ' Return the locations of the ticks'
911
+ """ Return the locations of the ticks"""
893
912
dmin , dmax = self .axis .get_data_interval ()
913
+ return self .tick_values (dmin , dmax )
914
+
915
+ def tick_values (self , dmin , dmax ):
894
916
return self .raise_if_exceeds (
895
917
np .arange (dmin + self .offset , dmax + 1 , self ._base ))
896
918
@@ -913,7 +935,17 @@ def __init__(self, locs, nbins=None):
913
935
self .nbins = max (self .nbins , 2 )
914
936
915
937
def __call__ (self ):
916
- 'Return the locations of the ticks'
938
+ return self .tick_values (None , None )
939
+
940
+ def tick_values (self , dmin , dmax ):
941
+ """"
942
+ Return the locations of the ticks.
943
+
944
+ .. note::
945
+
946
+ Because the values are fixed, dmin and dmax are not used in this method.
947
+
948
+ """
917
949
if self .nbins is None :
918
950
return self .locs
919
951
step = max (int (0.99 + len (self .locs ) / float (self .nbins )), 1 )
@@ -925,17 +957,26 @@ def __call__(self):
925
957
return self .raise_if_exceeds (ticks )
926
958
927
959
928
-
929
-
930
960
class NullLocator (Locator ):
931
961
"""
932
962
No ticks
933
963
"""
934
964
935
965
def __call__ (self ):
936
- 'Return the locations of the ticks'
966
+ return self .tick_values (None , None )
967
+
968
+ def tick_values (self , dmin , dmax ):
969
+ """"
970
+ Return the locations of the ticks.
971
+
972
+ .. note::
973
+
974
+ Because the values are Null, dmin and dmax are not used in this method.
975
+
976
+ """
937
977
return []
938
978
979
+
939
980
class LinearLocator (Locator ):
940
981
"""
941
982
Determine the tick locations
@@ -944,9 +985,8 @@ class LinearLocator(Locator):
944
985
number of ticks to make a nice tick partitioning. Thereafter the
945
986
number of ticks will be fixed so that interactive navigation will
946
987
be nice
947
- """
948
-
949
988
989
+ """
950
990
def __init__ (self , numticks = None , presets = None ):
951
991
"""
952
992
Use presets to set locs based on lom. A dict mapping vmin, vmax->locs
@@ -959,8 +999,10 @@ def __init__(self, numticks = None, presets=None):
959
999
960
1000
def __call__ (self ):
961
1001
'Return the locations of the ticks'
962
-
963
1002
vmin , vmax = self .axis .get_view_interval ()
1003
+ return self .tick_values (vmin , vmax )
1004
+
1005
+ def tick_values (self , vmin , vmax ):
964
1006
vmin , vmax = mtransforms .nonsingular (vmin , vmax , expander = 0.05 )
965
1007
if vmax < vmin :
966
1008
vmin , vmax = vmax , vmin
@@ -971,14 +1013,11 @@ def __call__(self):
971
1013
if self .numticks is None :
972
1014
self ._set_numticks ()
973
1015
974
-
975
-
976
1016
if self .numticks == 0 : return []
977
1017
ticklocs = np .linspace (vmin , vmax , self .numticks )
978
1018
979
1019
return self .raise_if_exceeds (ticklocs )
980
1020
981
-
982
1021
def _set_numticks (self ):
983
1022
self .numticks = 11 # todo; be smart here; this is just for dev
984
1023
@@ -1007,6 +1046,7 @@ def closeto(x,y):
1007
1046
if abs (x - y )< 1e-10 : return True
1008
1047
else : return False
1009
1048
1049
+
1010
1050
class Base :
1011
1051
'this solution has some hacks to deal with floating point inaccuracies'
1012
1052
def __init__ (self , base ):
@@ -1046,6 +1086,7 @@ def ge(self, x):
1046
1086
def get_base (self ):
1047
1087
return self ._base
1048
1088
1089
+
1049
1090
class MultipleLocator (Locator ):
1050
1091
"""
1051
1092
Set a tick on every integer that is multiple of base in the
@@ -1058,6 +1099,9 @@ def __init__(self, base=1.0):
1058
1099
def __call__ (self ):
1059
1100
'Return the locations of the ticks'
1060
1101
vmin , vmax = self .axis .get_view_interval ()
1102
+ return self .tick_values (vmin , vmax )
1103
+
1104
+ def tick_values (self , vmin , vmax ):
1061
1105
if vmax < vmin :
1062
1106
vmin , vmax = vmax , vmin
1063
1107
vmin = self ._base .ge (vmin )
@@ -1209,6 +1253,9 @@ def bin_boundaries(self, vmin, vmax):
1209
1253
1210
1254
def __call__ (self ):
1211
1255
vmin , vmax = self .axis .get_view_interval ()
1256
+ return self .tick_values (vmin , vmax )
1257
+
1258
+ def tick_values (self , vmin , vmax ):
1212
1259
vmin , vmax = mtransforms .nonsingular (vmin , vmax , expander = 1e-13 ,
1213
1260
tiny = 1e-14 )
1214
1261
locs = self .bin_boundaries (vmin , vmax )
@@ -1294,10 +1341,11 @@ def subs(self,subs):
1294
1341
1295
1342
def __call__ (self ):
1296
1343
'Return the locations of the ticks'
1297
- b = self ._base
1298
-
1299
1344
vmin , vmax = self .axis .get_view_interval ()
1345
+ return self .tick_values (vmin , vmax )
1300
1346
1347
+ def tick_values (self , vmin , vmax ):
1348
+ b = self ._base
1301
1349
# dummy axis has no axes attribute
1302
1350
if hasattr (self .axis , 'axes' ) and self .axis .axes .name == 'polar' :
1303
1351
vmax = math .ceil (math .log (vmax ) / math .log (b ))
@@ -1395,11 +1443,14 @@ def __init__(self, transform, subs=None):
1395
1443
1396
1444
def __call__ (self ):
1397
1445
'Return the locations of the ticks'
1446
+ # Note, these are untransformed coordinates
1447
+ vmin , vmax = self .axis .get_view_interval ()
1448
+ return self .tick_values (vmin , vmax )
1449
+
1450
+ def tick_values (self , vmin , vmax ):
1398
1451
b = self ._transform .base
1399
1452
t = self ._transform .linthresh
1400
1453
1401
- # Note, these are untransformed coordinates
1402
- vmin , vmax = self .axis .get_view_interval ()
1403
1454
if vmax < vmin :
1404
1455
vmin , vmax = vmax , vmin
1405
1456
@@ -1588,6 +1639,10 @@ def __call__(self):
1588
1639
1589
1640
return self .raise_if_exceeds (np .array (locs ))
1590
1641
1642
+ def tick_values (self , vmin , vmax ):
1643
+ raise NotImplementedError ('Cannot get tick locations for a '
1644
+ '%s type.' % type (self ))
1645
+
1591
1646
1592
1647
class OldAutoLocator (Locator ):
1593
1648
"""
@@ -1603,6 +1658,10 @@ def __call__(self):
1603
1658
self .refresh ()
1604
1659
return self .raise_if_exceeds (self ._locator ())
1605
1660
1661
+ def tick_values (self , vmin , vmax ):
1662
+ raise NotImplementedError ('Cannot get tick locations for a '
1663
+ '%s type.' % type (self ))
1664
+
1606
1665
def refresh (self ):
1607
1666
'refresh internal information based on current lim'
1608
1667
vmin , vmax = self .axis .get_view_interval ()
0 commit comments