@@ -1710,6 +1710,43 @@ def get_tick_space(self):
1710
1710
# Must be overridden in the subclass
1711
1711
raise NotImplementedError ()
1712
1712
1713
+ def _get_ticks_position (self ):
1714
+ """
1715
+ Helper for `XAxis.get_ticks_position` and `YAxis.get_ticks_position`.
1716
+
1717
+ Check the visibility of tick1line, label1, tick2line, and label2 on
1718
+ the first major and the first minor ticks, and return
1719
+
1720
+ - 1 if only tick1line and label1 are visible (which corresponds to
1721
+ "bottom" for the x-axis and "left" for the y-axis);
1722
+ - 2 if only tick2line and label2 are visible (which corresponds to
1723
+ "top" for the x-axis and "right" for the y-axis);
1724
+ - "default" if only tick1line, tick2line and label1 are visible;
1725
+ - "unknown" otherwise.
1726
+ """
1727
+ major = self .majorTicks [0 ]
1728
+ minor = self .minorTicks [0 ]
1729
+ if all (tick .tick1line .get_visible ()
1730
+ and not tick .tick2line .get_visible ()
1731
+ and tick .label1 .get_visible ()
1732
+ and not tick .label2 .get_visible ()
1733
+ for tick in [major , minor ]):
1734
+ return 1
1735
+ elif all (tick .tick2line .get_visible ()
1736
+ and not tick .tick1line .get_visible ()
1737
+ and tick .label2 .get_visible ()
1738
+ and not tick .label1 .get_visible ()
1739
+ for tick in [major , minor ]):
1740
+ return 2
1741
+ elif all (tick .tick1line .get_visible ()
1742
+ and tick .tick2line .get_visible ()
1743
+ and tick .label1 .get_visible ()
1744
+ and not tick .label2 .get_visible ()
1745
+ for tick in [major , minor ]):
1746
+ return "default"
1747
+ else :
1748
+ return "unknown"
1749
+
1713
1750
def get_label_position (self ):
1714
1751
"""
1715
1752
Return the label position (top or bottom)
@@ -2002,30 +2039,11 @@ def tick_bottom(self):
2002
2039
2003
2040
def get_ticks_position (self ):
2004
2041
"""
2005
- Return the ticks position (top, bottom, default or unknown)
2042
+ Return the ticks position (" top", " bottom", " default", or " unknown").
2006
2043
"""
2007
- major = self .majorTicks [0 ]
2008
- minor = self .minorTicks [0 ]
2009
- if all (tick .tick1line .get_visible ()
2010
- and not tick .tick2line .get_visible ()
2011
- and tick .label1 .get_visible ()
2012
- and not tick .label2 .get_visible ()
2013
- for tick in [major , minor ]):
2014
- return "bottom"
2015
- elif all (tick .tick2line .get_visible ()
2016
- and not tick .tick1line .get_visible ()
2017
- and tick .label2 .get_visible ()
2018
- and not tick .label1 .get_visible ()
2019
- for tick in [major , minor ]):
2020
- return "top"
2021
- elif all (tick .tick1line .get_visible ()
2022
- and tick .tick2line .get_visible ()
2023
- and tick .label1 .get_visible ()
2024
- and not tick .label2 .get_visible ()
2025
- for tick in [major , minor ]):
2026
- return "default"
2027
- else :
2028
- return "unknown"
2044
+ return {1 : "bottom" , 2 : "top" ,
2045
+ "default" : "default" , "unknown" : "unknown" }[
2046
+ self ._get_ticks_position ()]
2029
2047
2030
2048
def get_view_interval (self ):
2031
2049
'return the Interval instance for this axis view limits'
@@ -2383,33 +2401,11 @@ def tick_left(self):
2383
2401
2384
2402
def get_ticks_position (self ):
2385
2403
"""
2386
- Return the ticks position (left, right, both or unknown)
2387
- """
2388
- majt = self .majorTicks [0 ]
2389
- mT = self .minorTicks [0 ]
2390
-
2391
- majorRight = ((not majt .tick1On ) and majt .tick2On and
2392
- (not majt .label1On ) and majt .label2On )
2393
- minorRight = ((not mT .tick1On ) and mT .tick2On and
2394
- (not mT .label1On ) and mT .label2On )
2395
- if majorRight and minorRight :
2396
- return 'right'
2397
-
2398
- majorLeft = (majt .tick1On and (not majt .tick2On ) and
2399
- majt .label1On and (not majt .label2On ))
2400
- minorLeft = (mT .tick1On and (not mT .tick2On ) and
2401
- mT .label1On and (not mT .label2On ))
2402
- if majorLeft and minorLeft :
2403
- return 'left'
2404
-
2405
- majorDefault = (majt .tick1On and majt .tick2On and
2406
- majt .label1On and (not majt .label2On ))
2407
- minorDefault = (mT .tick1On and mT .tick2On and
2408
- mT .label1On and (not mT .label2On ))
2409
- if majorDefault and minorDefault :
2410
- return 'default'
2411
-
2412
- return 'unknown'
2404
+ Return the ticks position ("left", "right", "default", or "unknown").
2405
+ """
2406
+ return {1 : "left" , 2 : "right" ,
2407
+ "default" : "default" , "unknown" : "unknown" }[
2408
+ self ._get_ticks_position ()]
2413
2409
2414
2410
def get_view_interval (self ):
2415
2411
'return the Interval instance for this axis view limits'
0 commit comments