Skip to content

Commit d724662

Browse files
timhoffmstory645
andauthored
DOC: Add a warning on methods to access Tick parts (lines, labels, grid) (matplotlib#31691)
* DOC: Add a warning on methods to access Tick parts (lines, labels, grid) API docs in the same spirit as matplotlib#31682. Co-authored-by: hannah <story645@gmail.com> * Apply suggestions from code review Co-authored-by: hannah <story645@gmail.com> * Apply suggestions from code review Co-authored-by: hannah <story645@gmail.com> Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> * Apply suggestion from @timhoffm --------- Co-authored-by: hannah <story645@gmail.com>
1 parent e58558a commit d724662

1 file changed

Lines changed: 81 additions & 6 deletions

File tree

lib/matplotlib/axis.py

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,18 @@ def draw(self, renderer):
15721572
self.stale = False
15731573

15741574
def get_gridlines(self):
1575-
r"""Return this Axis' grid lines as a list of `.Line2D`\s."""
1575+
"""
1576+
Return this Axis' grid lines as a list of `.Line2D`.
1577+
1578+
.. warning::
1579+
1580+
Ticks and their constituent parts, including grid lines, are not
1581+
persistent. Various operations can create, delete, and modify the tick
1582+
instances; see :ref:`axes-tick-objects`.
1583+
1584+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1585+
to define and query grid styling; see :ref:`axes-ticks-styling`.
1586+
"""
15761587
ticks = self.get_major_ticks()
15771588
return cbook.silent_list('Line2D gridline',
15781589
[tick.gridline for tick in ticks])
@@ -1603,15 +1614,37 @@ def get_pickradius(self):
16031614
return self._pickradius
16041615

16051616
def get_majorticklabels(self):
1606-
"""Return this Axis' major tick labels, as a list of `~.text.Text`."""
1617+
"""
1618+
Return this Axis' major tick labels, as a list of `~.text.Text`.
1619+
1620+
.. warning::
1621+
1622+
Ticks and their constituent parts, including tick labels, are not
1623+
persistent. Various operations can create, delete, and modify the tick
1624+
instances; see :ref:`axes-tick-objects`.
1625+
1626+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1627+
to define and query tick styling; see :ref:`axes-ticks-styling`.
1628+
"""
16071629
self._update_ticks()
16081630
ticks = self.get_major_ticks()
16091631
labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
16101632
labels2 = [tick.label2 for tick in ticks if tick.label2.get_visible()]
16111633
return labels1 + labels2
16121634

16131635
def get_minorticklabels(self):
1614-
"""Return this Axis' minor tick labels, as a list of `~.text.Text`."""
1636+
"""
1637+
Return this Axis' minor tick labels, as a list of `~.text.Text`.
1638+
1639+
.. warning::
1640+
1641+
Ticks and their constituent parts, including tick labels, are not
1642+
persistent. Various operations can create, delete, and modify the tick
1643+
instances; see :ref:`axes-tick-objects`.
1644+
1645+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1646+
to define and query tick styling; see :ref:`axes-ticks-styling`.
1647+
"""
16151648
self._update_ticks()
16161649
ticks = self.get_minor_ticks()
16171650
labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
@@ -1622,6 +1655,15 @@ def get_ticklabels(self, minor=False, which=None):
16221655
"""
16231656
Get this Axis' tick labels.
16241657
1658+
.. warning::
1659+
1660+
Ticks and their constituent parts, including tick labels, are not
1661+
persistent. Various operations can create, delete, and modify the tick
1662+
instances; see :ref:`axes-tick-objects`.
1663+
1664+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1665+
to define and query tick styling; see :ref:`axes-ticks-styling`.
1666+
16251667
Parameters
16261668
----------
16271669
minor : bool
@@ -1650,7 +1692,18 @@ def get_ticklabels(self, minor=False, which=None):
16501692
return self.get_majorticklabels()
16511693

16521694
def get_majorticklines(self):
1653-
r"""Return this Axis' major tick lines as a list of `.Line2D`\s."""
1695+
"""
1696+
Return this Axis' major tick lines as a list of `.Line2D`.
1697+
1698+
.. warning::
1699+
1700+
Ticks and their constituent parts, including tick lines, are not
1701+
persistent. Various operations can create, delete, and modify the tick
1702+
instances; see :ref:`axes-tick-objects`.
1703+
1704+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1705+
to define and query tick styling; see :ref:`axes-ticks-styling`.
1706+
"""
16541707
lines = []
16551708
ticks = self.get_major_ticks()
16561709
for tick in ticks:
@@ -1659,7 +1712,18 @@ def get_majorticklines(self):
16591712
return cbook.silent_list('Line2D ticklines', lines)
16601713

16611714
def get_minorticklines(self):
1662-
r"""Return this Axis' minor tick lines as a list of `.Line2D`\s."""
1715+
"""
1716+
Return this Axis' minor tick lines as a list of `.Line2D`.
1717+
1718+
.. warning::
1719+
1720+
Ticks and their constituent parts, including tick lines, are not
1721+
persistent. Various operations can create, delete, and modify the tick
1722+
instances; see :ref:`axes-tick-objects`.
1723+
1724+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1725+
to define and query tick styling; see :ref:`axes-ticks-styling`.
1726+
"""
16631727
lines = []
16641728
ticks = self.get_minor_ticks()
16651729
for tick in ticks:
@@ -1668,7 +1732,18 @@ def get_minorticklines(self):
16681732
return cbook.silent_list('Line2D ticklines', lines)
16691733

16701734
def get_ticklines(self, minor=False):
1671-
r"""Return this Axis' tick lines as a list of `.Line2D`\s."""
1735+
"""
1736+
Return this Axis' tick lines as a list of `.Line2D`.
1737+
1738+
.. warning::
1739+
1740+
Ticks and their constituent parts, including tick lines, are not
1741+
persistent. Various operations can create, delete, and modify the tick
1742+
instances; see :ref:`axes-tick-objects`.
1743+
1744+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1745+
to define and query tick styling; see :ref:`axes-ticks-styling`.
1746+
"""
16721747
if minor:
16731748
return self.get_minorticklines()
16741749
return self.get_majorticklines()

0 commit comments

Comments
 (0)