Skip to content

Commit 66af5e0

Browse files
timhoffmstory645
andcommitted
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>
1 parent c6377d0 commit 66af5e0

1 file changed

Lines changed: 95 additions & 6 deletions

File tree

lib/matplotlib/axis.py

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,20 @@ 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+
persistent. Various operations can create, delete, and modify the tick
1561+
instances; see :ref:`axes-tick-objects`.
1562+
1563+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1564+
to define and query grid styling; see :ref:`axes-tick-styling`. Working
1565+
directly with the grid line objects is typically not necessary, except for
1566+
very special customizations.
1567+
"""
15551568
ticks = self.get_major_ticks()
15561569
return cbook.silent_list('Line2D gridline',
15571570
[tick.gridline for tick in ticks])
@@ -1582,15 +1595,41 @@ def get_pickradius(self):
15821595
return self._pickradius
15831596

15841597
def get_majorticklabels(self):
1585-
"""Return this Axis' major tick labels, as a list of `~.text.Text`."""
1598+
"""
1599+
Return this Axis' major tick labels, as a list of `~.text.Text`.
1600+
1601+
.. warning::
1602+
1603+
Ticks and their constituent parts, including tick labels, are not
1604+
persistent. Various operations can create, delete, and modify the tick
1605+
instances; see :ref:`axes-tick-objects`.
1606+
1607+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1608+
to define and query tick styling; see :ref:`axes-tick-styling`. Working
1609+
directly with the tick text objects is typically not necessary, except for
1610+
very special customizations.
1611+
"""
15861612
self._update_ticks()
15871613
ticks = self.get_major_ticks()
15881614
labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
15891615
labels2 = [tick.label2 for tick in ticks if tick.label2.get_visible()]
15901616
return labels1 + labels2
15911617

15921618
def get_minorticklabels(self):
1593-
"""Return this Axis' minor tick labels, as a list of `~.text.Text`."""
1619+
"""
1620+
Return this Axis' minor tick labels, as a list of `~.text.Text`.
1621+
1622+
.. warning::
1623+
1624+
Ticks and their constituent parts, including tick labels, are not
1625+
persistent. Various operations can create, delete, and modify the tick
1626+
instances; see :ref:`axes-tick-objects`.
1627+
1628+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1629+
to define and query tick styling; see :ref:`axes-tick-styling`. Working
1630+
directly with the tick text objects is typically not necessary, except for
1631+
very special customizations.
1632+
"""
15941633
self._update_ticks()
15951634
ticks = self.get_minor_ticks()
15961635
labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
@@ -1601,6 +1640,17 @@ def get_ticklabels(self, minor=False, which=None):
16011640
"""
16021641
Get this Axis' tick labels.
16031642
1643+
.. warning::
1644+
1645+
Ticks and their constituent parts, including tick labels, are not
1646+
persistent. Various operations can create, delete, and modify the tick
1647+
instances; see :ref:`axes-tick-objects`.
1648+
1649+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1650+
to define and query tick styling; see :ref:`axes-tick-styling`. Working
1651+
directly with the tick text objects is typically not necessary, except for
1652+
very special customizations.
1653+
16041654
Parameters
16051655
----------
16061656
minor : bool
@@ -1629,7 +1679,20 @@ def get_ticklabels(self, minor=False, which=None):
16291679
return self.get_majorticklabels()
16301680

16311681
def get_majorticklines(self):
1632-
r"""Return this Axis' major tick lines as a list of `.Line2D`\s."""
1682+
"""
1683+
Return this Axis' major tick lines as a list of `.Line2D`.
1684+
1685+
.. warning::
1686+
1687+
Ticks and their constituent parts, including tick lines, are not
1688+
persistent. Various operations can create, delete, and modify the tick
1689+
instances; see :ref:`axes-tick-objects`.
1690+
1691+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1692+
to define and query tick styling; see :ref:`axes-tick-styling`. Working
1693+
directly with the tick line objects is typically not necessary, except for
1694+
very special customizations.
1695+
"""
16331696
lines = []
16341697
ticks = self.get_major_ticks()
16351698
for tick in ticks:
@@ -1638,7 +1701,20 @@ def get_majorticklines(self):
16381701
return cbook.silent_list('Line2D ticklines', lines)
16391702

16401703
def get_minorticklines(self):
1641-
r"""Return this Axis' minor tick lines as a list of `.Line2D`\s."""
1704+
"""
1705+
Return this Axis' minor tick lines as a list of `.Line2D`.
1706+
1707+
.. warning::
1708+
1709+
Ticks and their constituent parts, including tick lines, are not
1710+
persistent. Various operations can create, delete, and modify the tick
1711+
instances; see :ref:`axes-tick-objects`.
1712+
1713+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1714+
to define and query tick styling; see :ref:`axes-tick-styling`. Working
1715+
directly with the tick line objects is typically not necessary, except for
1716+
very special customizations.
1717+
"""
16421718
lines = []
16431719
ticks = self.get_minor_ticks()
16441720
for tick in ticks:
@@ -1647,7 +1723,20 @@ def get_minorticklines(self):
16471723
return cbook.silent_list('Line2D ticklines', lines)
16481724

16491725
def get_ticklines(self, minor=False):
1650-
r"""Return this Axis' tick lines as a list of `.Line2D`\s."""
1726+
"""
1727+
Return this Axis' tick lines as a list of `.Line2D`.
1728+
1729+
.. warning::
1730+
1731+
Ticks and their constituent parts, including tick lines, are not
1732+
persistent. Various operations can create, delete, and modify the tick
1733+
instances; see :ref:`axes-tick-objects`.
1734+
1735+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1736+
to define and query tick styling; see :ref:`axes-tick-styling`. Working
1737+
directly with the tick line objects is typically not necessary, except for
1738+
very special customizations.
1739+
"""
16511740
if minor:
16521741
return self.get_minorticklines()
16531742
return self.get_majorticklines()

0 commit comments

Comments
 (0)