Skip to content

Commit d27462a

Browse files
committed
DOC: Add a warning on methods to access Tick parts (lines, labels, grid)
API docs in the same spirit as matplotlib#31682.
1 parent c6377d0 commit d27462a

1 file changed

Lines changed: 88 additions & 10 deletions

File tree

lib/matplotlib/axis.py

Lines changed: 88 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,18 @@ def draw(self, renderer):
15511551
self.stale = False
15521552

15531553
def get_gridlines(self):
1554-
r"""Return this Axis' grid lines as a list of `.Line2D`\s."""
1554+
"""
1555+
Return this Axis' grid lines as a list of `.Line2D`.
1556+
1557+
.. warning::
1558+
1559+
Ticks and their constituent parts, including grid lines, are not
1560+
guaranteed to be persistent. Various operations can create, delete and
1561+
modify the Tick instances.
1562+
1563+
Consider using `.Axis.set_tick_params` / `.Axis.get_tick_params` to
1564+
define and query grid styling.
1565+
"""
15551566
ticks = self.get_major_ticks()
15561567
return cbook.silent_list('Line2D gridline',
15571568
[tick.gridline for tick in ticks])
@@ -1582,15 +1593,39 @@ def get_pickradius(self):
15821593
return self._pickradius
15831594

15841595
def get_majorticklabels(self):
1585-
"""Return this Axis' major tick labels, as a list of `~.text.Text`."""
1596+
"""
1597+
Return this Axis' major tick labels, as a list of `~.text.Text`.
1598+
1599+
.. warning::
1600+
1601+
Ticks and their constituent parts, including tick labels, are not
1602+
guaranteed to be persistent. Various operations can create, delete and
1603+
modify the Tick instances.
1604+
1605+
Access to the underlying `.Text` objects is typically not necessary.
1606+
See the user guide :ref:`user_axes_ticks` for recommended ways of
1607+
defining and styling ticks.
1608+
"""
15861609
self._update_ticks()
15871610
ticks = self.get_major_ticks()
15881611
labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
15891612
labels2 = [tick.label2 for tick in ticks if tick.label2.get_visible()]
15901613
return labels1 + labels2
15911614

15921615
def get_minorticklabels(self):
1593-
"""Return this Axis' minor tick labels, as a list of `~.text.Text`."""
1616+
"""
1617+
Return this Axis' minor tick labels, as a list of `~.text.Text`.
1618+
1619+
.. warning::
1620+
1621+
Ticks and their constituent parts, including tick labels, are not
1622+
guaranteed to be persistent. Various operations can create, delete and
1623+
modify the Tick instances.
1624+
1625+
Access to the underlying `.Text` objects is typically not necessary.
1626+
See the user guide :ref:`user_axes_ticks` for recmmended ways of
1627+
defining and styling ticks.
1628+
"""
15941629
self._update_ticks()
15951630
ticks = self.get_minor_ticks()
15961631
labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
@@ -1601,6 +1636,16 @@ def get_ticklabels(self, minor=False, which=None):
16011636
"""
16021637
Get this Axis' tick labels.
16031638
1639+
.. warning::
1640+
1641+
Ticks and their constituent parts, including tick labels, are not
1642+
guaranteed to be persistent. Various operations can create, delete and
1643+
modify the Tick instances.
1644+
1645+
Access to the underlying `.Text` objects is typically not necessary.
1646+
See the user guide :ref:`user_axes_ticks` for recommended ways of
1647+
defining and styling ticks.
1648+
16041649
Parameters
16051650
----------
16061651
minor : bool
@@ -1629,7 +1674,18 @@ def get_ticklabels(self, minor=False, which=None):
16291674
return self.get_majorticklabels()
16301675

16311676
def get_majorticklines(self):
1632-
r"""Return this Axis' major tick lines as a list of `.Line2D`\s."""
1677+
"""
1678+
Return this Axis' major tick lines as a list of `.Line2D`.
1679+
1680+
.. warning::
1681+
1682+
Ticks and their constituent parts, including tick lines, are not
1683+
guaranteed to be persistent. Various operations can create, delete and
1684+
modify the Tick instances.
1685+
1686+
Consider using `.Axis.set_tick_params` / `.Axis.get_tick_params` to
1687+
define and query tick styling.
1688+
"""
16331689
lines = []
16341690
ticks = self.get_major_ticks()
16351691
for tick in ticks:
@@ -1638,7 +1694,18 @@ def get_majorticklines(self):
16381694
return cbook.silent_list('Line2D ticklines', lines)
16391695

16401696
def get_minorticklines(self):
1641-
r"""Return this Axis' minor tick lines as a list of `.Line2D`\s."""
1697+
"""
1698+
Return this Axis' minor tick lines as a list of `.Line2D`.
1699+
1700+
.. warning::
1701+
1702+
Ticks and their constituent parts, including tick lines, are not
1703+
guaranteed to be persistent. Various operations can create, delete and
1704+
modify the Tick instances.
1705+
1706+
Consider using `.Axis.set_tick_params` / `.Axis.get_tick_params` to
1707+
define and query tick styling.
1708+
"""
16421709
lines = []
16431710
ticks = self.get_minor_ticks()
16441711
for tick in ticks:
@@ -1647,7 +1714,18 @@ def get_minorticklines(self):
16471714
return cbook.silent_list('Line2D ticklines', lines)
16481715

16491716
def get_ticklines(self, minor=False):
1650-
r"""Return this Axis' tick lines as a list of `.Line2D`\s."""
1717+
"""
1718+
Return this Axis' tick lines as a list of `.Line2D`.
1719+
1720+
.. warning::
1721+
1722+
Ticks and their constituent parts, including tick lines, are not
1723+
guaranteed to be persistent. Various operations can create, delete and
1724+
modify the Tick instances.
1725+
1726+
Consider using `.Axis.set_tick_params` / `.Axis.get_tick_params` to
1727+
define and query tick styling.
1728+
"""
16511729
if minor:
16521730
return self.get_minorticklines()
16531731
return self.get_majorticklines()
@@ -1774,8 +1852,8 @@ def get_minor_formatter(self):
17741852
return self.minor.formatter
17751853

17761854
def get_major_ticks(self, numticks=None):
1777-
r"""
1778-
Return the list of major `.Tick`\s.
1855+
"""
1856+
Return the list of major `.Tick`.
17791857
17801858
.. warning::
17811859
@@ -1800,8 +1878,8 @@ def get_major_ticks(self, numticks=None):
18001878
return self.majorTicks[:numticks]
18011879

18021880
def get_minor_ticks(self, numticks=None):
1803-
r"""
1804-
Return the list of minor `.Tick`\s.
1881+
"""
1882+
Return the list of minor `.Tick`.
18051883
18061884
.. warning::
18071885

0 commit comments

Comments
 (0)