Skip to content

Commit 67114f8

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 b825c6d commit 67114f8

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
@@ -1572,7 +1572,20 @@ 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`. Working
1586+
directly with the grid line objects is typically not necessary, except for
1587+
very special customizations.
1588+
"""
15761589
ticks = self.get_major_ticks()
15771590
return cbook.silent_list('Line2D gridline',
15781591
[tick.gridline for tick in ticks])
@@ -1603,15 +1616,41 @@ def get_pickradius(self):
16031616
return self._pickradius
16041617

16051618
def get_majorticklabels(self):
1606-
"""Return this Axis' major tick labels, as a list of `~.text.Text`."""
1619+
"""
1620+
Return this Axis' major 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-ticks-styling`. Working
1630+
directly with the tick text objects is typically not necessary, except for
1631+
very special customizations.
1632+
"""
16071633
self._update_ticks()
16081634
ticks = self.get_major_ticks()
16091635
labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
16101636
labels2 = [tick.label2 for tick in ticks if tick.label2.get_visible()]
16111637
return labels1 + labels2
16121638

16131639
def get_minorticklabels(self):
1614-
"""Return this Axis' minor tick labels, as a list of `~.text.Text`."""
1640+
"""
1641+
Return this Axis' minor tick labels, as a list of `~.text.Text`.
1642+
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-ticks-styling`. Working
1651+
directly with the tick text objects is typically not necessary, except for
1652+
very special customizations.
1653+
"""
16151654
self._update_ticks()
16161655
ticks = self.get_minor_ticks()
16171656
labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
@@ -1622,6 +1661,17 @@ def get_ticklabels(self, minor=False, which=None):
16221661
"""
16231662
Get this Axis' tick labels.
16241663
1664+
.. warning::
1665+
1666+
Ticks and their constituent parts, including tick labels, are not
1667+
persistent. Various operations can create, delete, and modify the tick
1668+
instances; see :ref:`axes-tick-objects`.
1669+
1670+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1671+
to define and query tick styling; see :ref:`axes-ticks-styling`. Working
1672+
directly with the tick text objects is typically not necessary, except for
1673+
very special customizations.
1674+
16251675
Parameters
16261676
----------
16271677
minor : bool
@@ -1650,7 +1700,20 @@ def get_ticklabels(self, minor=False, which=None):
16501700
return self.get_majorticklabels()
16511701

16521702
def get_majorticklines(self):
1653-
r"""Return this Axis' major tick lines as a list of `.Line2D`\s."""
1703+
"""
1704+
Return this Axis' major tick lines as a list of `.Line2D`.
1705+
1706+
.. warning::
1707+
1708+
Ticks and their constituent parts, including tick lines, are not
1709+
persistent. Various operations can create, delete, and modify the tick
1710+
instances; see :ref:`axes-tick-objects`.
1711+
1712+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1713+
to define and query tick styling; see :ref:`axes-ticks-styling`. Working
1714+
directly with the tick line objects is typically not necessary, except for
1715+
very special customizations.
1716+
"""
16541717
lines = []
16551718
ticks = self.get_major_ticks()
16561719
for tick in ticks:
@@ -1659,7 +1722,20 @@ def get_majorticklines(self):
16591722
return cbook.silent_list('Line2D ticklines', lines)
16601723

16611724
def get_minorticklines(self):
1662-
r"""Return this Axis' minor tick lines as a list of `.Line2D`\s."""
1725+
"""
1726+
Return this Axis' minor tick lines as a list of `.Line2D`.
1727+
1728+
.. warning::
1729+
1730+
Ticks and their constituent parts, including tick lines, are not
1731+
persistent. Various operations can create, delete, and modify the tick
1732+
instances; see :ref:`axes-tick-objects`.
1733+
1734+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1735+
to define and query tick styling; see :ref:`axes-ticks-styling`. Working
1736+
directly with the tick line objects is typically not necessary, except for
1737+
very special customizations.
1738+
"""
16631739
lines = []
16641740
ticks = self.get_minor_ticks()
16651741
for tick in ticks:
@@ -1668,7 +1744,20 @@ def get_minorticklines(self):
16681744
return cbook.silent_list('Line2D ticklines', lines)
16691745

16701746
def get_ticklines(self, minor=False):
1671-
r"""Return this Axis' tick lines as a list of `.Line2D`\s."""
1747+
"""
1748+
Return this Axis' tick lines as a list of `.Line2D`.
1749+
1750+
.. warning::
1751+
1752+
Ticks and their constituent parts, including tick lines, are not
1753+
persistent. Various operations can create, delete, and modify the tick
1754+
instances; see :ref:`axes-tick-objects`.
1755+
1756+
You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1757+
to define and query tick styling; see :ref:`axes-ticks-styling`. Working
1758+
directly with the tick line objects is typically not necessary, except for
1759+
very special customizations.
1760+
"""
16721761
if minor:
16731762
return self.get_minorticklines()
16741763
return self.get_majorticklines()

0 commit comments

Comments
 (0)