Skip to content

Commit 47de85d

Browse files
timhoffmmeeseeksmachine
authored andcommitted
Backport PR matplotlib#31691: DOC: Add a warning on methods to access Tick parts (lines, labels, grid)
1 parent 70a0d27 commit 47de85d

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
@@ -1492,7 +1492,18 @@ def draw(self, renderer):
14921492
self.stale = False
14931493

14941494
def get_gridlines(self):
1495-
r"""Return this Axis' grid lines as a list of `.Line2D`\s."""
1495+
"""
1496+
Return this Axis' grid lines as a list of `.Line2D`.
1497+
1498+
.. warning::
1499+
1500+
Ticks and their constituent parts, including grid lines, are not
1501+
persistent. Various operations can create, delete, and modify the tick
1502+
instances; see :ref:`axes-tick-objects`.
1503+
1504+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1505+
to define and query grid styling; see :ref:`axes-ticks-styling`.
1506+
"""
14961507
ticks = self.get_major_ticks()
14971508
return cbook.silent_list('Line2D gridline',
14981509
[tick.gridline for tick in ticks])
@@ -1523,15 +1534,37 @@ def get_pickradius(self):
15231534
return self._pickradius
15241535

15251536
def get_majorticklabels(self):
1526-
"""Return this Axis' major tick labels, as a list of `~.text.Text`."""
1537+
"""
1538+
Return this Axis' major tick labels, as a list of `~.text.Text`.
1539+
1540+
.. warning::
1541+
1542+
Ticks and their constituent parts, including tick labels, are not
1543+
persistent. Various operations can create, delete, and modify the tick
1544+
instances; see :ref:`axes-tick-objects`.
1545+
1546+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1547+
to define and query tick styling; see :ref:`axes-ticks-styling`.
1548+
"""
15271549
self._update_ticks()
15281550
ticks = self.get_major_ticks()
15291551
labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
15301552
labels2 = [tick.label2 for tick in ticks if tick.label2.get_visible()]
15311553
return labels1 + labels2
15321554

15331555
def get_minorticklabels(self):
1534-
"""Return this Axis' minor tick labels, as a list of `~.text.Text`."""
1556+
"""
1557+
Return this Axis' minor tick labels, as a list of `~.text.Text`.
1558+
1559+
.. warning::
1560+
1561+
Ticks and their constituent parts, including tick labels, are not
1562+
persistent. Various operations can create, delete, and modify the tick
1563+
instances; see :ref:`axes-tick-objects`.
1564+
1565+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1566+
to define and query tick styling; see :ref:`axes-ticks-styling`.
1567+
"""
15351568
self._update_ticks()
15361569
ticks = self.get_minor_ticks()
15371570
labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
@@ -1542,6 +1575,15 @@ def get_ticklabels(self, minor=False, which=None):
15421575
"""
15431576
Get this Axis' tick labels.
15441577
1578+
.. warning::
1579+
1580+
Ticks and their constituent parts, including tick labels, 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 tick styling; see :ref:`axes-ticks-styling`.
1586+
15451587
Parameters
15461588
----------
15471589
minor : bool
@@ -1570,7 +1612,18 @@ def get_ticklabels(self, minor=False, which=None):
15701612
return self.get_majorticklabels()
15711613

15721614
def get_majorticklines(self):
1573-
r"""Return this Axis' major tick lines as a list of `.Line2D`\s."""
1615+
"""
1616+
Return this Axis' major tick lines as a list of `.Line2D`.
1617+
1618+
.. warning::
1619+
1620+
Ticks and their constituent parts, including tick lines, are not
1621+
persistent. Various operations can create, delete, and modify the tick
1622+
instances; see :ref:`axes-tick-objects`.
1623+
1624+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1625+
to define and query tick styling; see :ref:`axes-ticks-styling`.
1626+
"""
15741627
lines = []
15751628
ticks = self.get_major_ticks()
15761629
for tick in ticks:
@@ -1579,7 +1632,18 @@ def get_majorticklines(self):
15791632
return cbook.silent_list('Line2D ticklines', lines)
15801633

15811634
def get_minorticklines(self):
1582-
r"""Return this Axis' minor tick lines as a list of `.Line2D`\s."""
1635+
"""
1636+
Return this Axis' minor tick lines as a list of `.Line2D`.
1637+
1638+
.. warning::
1639+
1640+
Ticks and their constituent parts, including tick lines, are not
1641+
persistent. Various operations can create, delete, and modify the tick
1642+
instances; see :ref:`axes-tick-objects`.
1643+
1644+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1645+
to define and query tick styling; see :ref:`axes-ticks-styling`.
1646+
"""
15831647
lines = []
15841648
ticks = self.get_minor_ticks()
15851649
for tick in ticks:
@@ -1588,7 +1652,18 @@ def get_minorticklines(self):
15881652
return cbook.silent_list('Line2D ticklines', lines)
15891653

15901654
def get_ticklines(self, minor=False):
1591-
r"""Return this Axis' tick lines as a list of `.Line2D`\s."""
1655+
"""
1656+
Return this Axis' tick lines as a list of `.Line2D`.
1657+
1658+
.. warning::
1659+
1660+
Ticks and their constituent parts, including tick lines, 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+
"""
15921667
if minor:
15931668
return self.get_minorticklines()
15941669
return self.get_majorticklines()

0 commit comments

Comments
 (0)