Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c2e84f

Browse files
committed
Update and factor out Axis.get_tick_positions.
YAxis.get_ticks_position had not been updated after the deprecation of label1On. Fix that by making it share its implementation with XAxis.get_ticks_position.
1 parent 623b789 commit 3c2e84f

File tree

1 file changed

+46
-50
lines changed

1 file changed

+46
-50
lines changed

lib/matplotlib/axis.py

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,43 @@ def get_tick_space(self):
17101710
# Must be overridden in the subclass
17111711
raise NotImplementedError()
17121712

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+
17131750
def get_label_position(self):
17141751
"""
17151752
Return the label position (top or bottom)
@@ -2002,30 +2039,11 @@ def tick_bottom(self):
20022039

20032040
def get_ticks_position(self):
20042041
"""
2005-
Return the ticks position (top, bottom, default or unknown)
2042+
Return the ticks position ("top", "bottom", "default", or "unknown").
20062043
"""
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()]
20292047

20302048
def get_view_interval(self):
20312049
'return the Interval instance for this axis view limits'
@@ -2383,33 +2401,11 @@ def tick_left(self):
23832401

23842402
def get_ticks_position(self):
23852403
"""
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()]
24132409

24142410
def get_view_interval(self):
24152411
'return the Interval instance for this axis view limits'

0 commit comments

Comments
 (0)