Skip to content

Commit 0192c3b

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 0192c3b

1 file changed

Lines changed: 85 additions & 10 deletions

File tree

lib/matplotlib/axis.py

Lines changed: 85 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,37 @@ 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 defining and styling ticks.
1607+
"""
15861608
self._update_ticks()
15871609
ticks = self.get_major_ticks()
15881610
labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
15891611
labels2 = [tick.label2 for tick in ticks if tick.label2.get_visible()]
15901612
return labels1 + labels2
15911613

15921614
def get_minorticklabels(self):
1593-
"""Return this Axis' minor tick labels, as a list of `~.text.Text`."""
1615+
"""
1616+
Return this Axis' minor tick labels, as a list of `~.text.Text`.
1617+
1618+
.. warning::
1619+
1620+
Ticks and their constituent parts, including tick labels, are not
1621+
guaranteed to be persistent. Various operations can create, delete and
1622+
modify the Tick instances.
1623+
1624+
Access to the underlying `.Text` objects is typically not necessary.
1625+
See the user guide :ref:`user_axes_ticks` for defining and styling ticks.
1626+
"""
15941627
self._update_ticks()
15951628
ticks = self.get_minor_ticks()
15961629
labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
@@ -1601,6 +1634,15 @@ def get_ticklabels(self, minor=False, which=None):
16011634
"""
16021635
Get this Axis' tick labels.
16031636
1637+
.. warning::
1638+
1639+
Ticks and their constituent parts, including tick labels, are not
1640+
guaranteed to be persistent. Various operations can create, delete and
1641+
modify the Tick instances.
1642+
1643+
Access to the underlying `.Text` objects is typically not necessary.
1644+
See the user guide :ref:`user_axes_ticks` for defining and styling ticks.
1645+
16041646
Parameters
16051647
----------
16061648
minor : bool
@@ -1629,7 +1671,18 @@ def get_ticklabels(self, minor=False, which=None):
16291671
return self.get_majorticklabels()
16301672

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

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

16491713
def get_ticklines(self, minor=False):
1650-
r"""Return this Axis' tick lines as a list of `.Line2D`\s."""
1714+
"""
1715+
Return this Axis' tick lines as a list of `.Line2D`.
1716+
1717+
.. warning::
1718+
1719+
Ticks and their constituent parts, including tick lines, are not
1720+
guaranteed to be persistent. Various operations can create, delete and
1721+
modify the Tick instances.
1722+
1723+
Consider using `.Axis.set_tick_params` / `.Axis.get_tick_params` to
1724+
define and query tick styling.
1725+
"""
16511726
if minor:
16521727
return self.get_minorticklines()
16531728
return self.get_majorticklines()
@@ -1774,8 +1849,8 @@ def get_minor_formatter(self):
17741849
return self.minor.formatter
17751850

17761851
def get_major_ticks(self, numticks=None):
1777-
r"""
1778-
Return the list of major `.Tick`\s.
1852+
"""
1853+
Return the list of major `.Tick`.
17791854
17801855
.. warning::
17811856
@@ -1800,8 +1875,8 @@ def get_major_ticks(self, numticks=None):
18001875
return self.majorTicks[:numticks]
18011876

18021877
def get_minor_ticks(self, numticks=None):
1803-
r"""
1804-
Return the list of minor `.Tick`\s.
1878+
"""
1879+
Return the list of minor `.Tick`.
18051880
18061881
.. warning::
18071882

0 commit comments

Comments
 (0)