@@ -1769,6 +1769,43 @@ def get_tick_space(self):
17691769 # Must be overridden in the subclass
17701770 raise NotImplementedError ()
17711771
1772+ def _get_ticks_position (self ):
1773+ """
1774+ Helper for `XAxis.get_ticks_position` and `YAxis.get_ticks_position`.
1775+
1776+ Check the visibility of tick1line, label1, tick2line, and label2 on
1777+ the first major and the first minor ticks, and return
1778+
1779+ - 1 if only tick1line and label1 are visible (which corresponds to
1780+ "bottom" for the x-axis and "left" for the y-axis);
1781+ - 2 if only tick2line and label2 are visible (which corresponds to
1782+ "top" for the x-axis and "right" for the y-axis);
1783+ - "default" if only tick1line, tick2line and label1 are visible;
1784+ - "unknown" otherwise.
1785+ """
1786+ major = self .majorTicks [0 ]
1787+ minor = self .minorTicks [0 ]
1788+ if all (tick .tick1line .get_visible ()
1789+ and not tick .tick2line .get_visible ()
1790+ and tick .label1 .get_visible ()
1791+ and not tick .label2 .get_visible ()
1792+ for tick in [major , minor ]):
1793+ return 1
1794+ elif all (tick .tick2line .get_visible ()
1795+ and not tick .tick1line .get_visible ()
1796+ and tick .label2 .get_visible ()
1797+ and not tick .label1 .get_visible ()
1798+ for tick in [major , minor ]):
1799+ return 2
1800+ elif all (tick .tick1line .get_visible ()
1801+ and tick .tick2line .get_visible ()
1802+ and tick .label1 .get_visible ()
1803+ and not tick .label2 .get_visible ()
1804+ for tick in [major , minor ]):
1805+ return "default"
1806+ else :
1807+ return "unknown"
1808+
17721809 def get_label_position (self ):
17731810 """
17741811 Return the label position (top or bottom)
@@ -2061,30 +2098,11 @@ def tick_bottom(self):
20612098
20622099 def get_ticks_position (self ):
20632100 """
2064- Return the ticks position (top, bottom, default or unknown)
2101+ Return the ticks position (" top", " bottom", " default", or " unknown").
20652102 """
2066- major = self .majorTicks [0 ]
2067- minor = self .minorTicks [0 ]
2068- if all (tick .tick1line .get_visible ()
2069- and not tick .tick2line .get_visible ()
2070- and tick .label1 .get_visible ()
2071- and not tick .label2 .get_visible ()
2072- for tick in [major , minor ]):
2073- return "bottom"
2074- elif all (tick .tick2line .get_visible ()
2075- and not tick .tick1line .get_visible ()
2076- and tick .label2 .get_visible ()
2077- and not tick .label1 .get_visible ()
2078- for tick in [major , minor ]):
2079- return "top"
2080- elif all (tick .tick1line .get_visible ()
2081- and tick .tick2line .get_visible ()
2082- and tick .label1 .get_visible ()
2083- and not tick .label2 .get_visible ()
2084- for tick in [major , minor ]):
2085- return "default"
2086- else :
2087- return "unknown"
2103+ return {1 : "bottom" , 2 : "top" ,
2104+ "default" : "default" , "unknown" : "unknown" }[
2105+ self ._get_ticks_position ()]
20882106
20892107 def get_view_interval (self ):
20902108 # docstring inherited
@@ -2434,33 +2452,11 @@ def tick_left(self):
24342452
24352453 def get_ticks_position (self ):
24362454 """
2437- Return the ticks position (left, right, both or unknown)
2438- """
2439- majt = self .majorTicks [0 ]
2440- mT = self .minorTicks [0 ]
2441-
2442- majorRight = ((not majt .tick1On ) and majt .tick2On and
2443- (not majt .label1On ) and majt .label2On )
2444- minorRight = ((not mT .tick1On ) and mT .tick2On and
2445- (not mT .label1On ) and mT .label2On )
2446- if majorRight and minorRight :
2447- return 'right'
2448-
2449- majorLeft = (majt .tick1On and (not majt .tick2On ) and
2450- majt .label1On and (not majt .label2On ))
2451- minorLeft = (mT .tick1On and (not mT .tick2On ) and
2452- mT .label1On and (not mT .label2On ))
2453- if majorLeft and minorLeft :
2454- return 'left'
2455-
2456- majorDefault = (majt .tick1On and majt .tick2On and
2457- majt .label1On and (not majt .label2On ))
2458- minorDefault = (mT .tick1On and mT .tick2On and
2459- mT .label1On and (not mT .label2On ))
2460- if majorDefault and minorDefault :
2461- return 'default'
2462-
2463- return 'unknown'
2455+ Return the ticks position ("left", "right", "default", or "unknown").
2456+ """
2457+ return {1 : "left" , 2 : "right" ,
2458+ "default" : "default" , "unknown" : "unknown" }[
2459+ self ._get_ticks_position ()]
24642460
24652461 def get_view_interval (self ):
24662462 # docstring inherited
0 commit comments