Skip to content

Backport PR #26436 on branch v3.7.x (DOC: Add a warning that ticks are not persistent) #26439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,18 @@ class Axis(martist.Artist):
The acceptance radius for containment tests. See also `.Axis.contains`.
majorTicks : list of `.Tick`
The major ticks.

.. warning::

Ticks are not guaranteed to be persistent. Various operations
can create, delete and modify the Tick instances. There is an
imminent risk that changes to individual ticks will not
survive if you work on the figure further (including also
panning/zooming on a displayed figure).

Working on the individual ticks is a method of last resort.
Use `.set_tick_params` instead if possible.

minorTicks : list of `.Tick`
The minor ticks.
"""
Expand Down Expand Up @@ -1593,7 +1605,20 @@ def get_minor_formatter(self):
return self.minor.formatter

def get_major_ticks(self, numticks=None):
r"""Return the list of major `.Tick`\s."""
r"""
Return the list of major `.Tick`\s.

.. warning::

Ticks are not guaranteed to be persistent. Various operations
can create, delete and modify the Tick instances. There is an
imminent risk that changes to individual ticks will not
survive if you work on the figure further (including also
panning/zooming on a displayed figure).

Working on the individual ticks is a method of last resort.
Use `.set_tick_params` instead if possible.
"""
if numticks is None:
numticks = len(self.get_majorticklocs())

Expand All @@ -1606,7 +1631,20 @@ def get_major_ticks(self, numticks=None):
return self.majorTicks[:numticks]

def get_minor_ticks(self, numticks=None):
r"""Return the list of minor `.Tick`\s."""
r"""
Return the list of minor `.Tick`\s.

.. warning::

Ticks are not guaranteed to be persistent. Various operations
can create, delete and modify the Tick instances. There is an
imminent risk that changes to individual ticks will not
survive if you work on the figure further (including also
panning/zooming on a displayed figure).

Working on the individual ticks is a method of last resort.
Use `.set_tick_params` instead if possible.
"""
if numticks is None:
numticks = len(self.get_minorticklocs())

Expand Down Expand Up @@ -1949,6 +1987,17 @@ def set_ticklabels(self, labels, *, minor=False, fontdict=None, **kwargs):
**kwargs
Text properties.

.. warning::

This only sets the properties of the current ticks.
Ticks are not guaranteed to be persistent. Various operations
can create, delete and modify the Tick instances. There is an
imminent risk that these settings can get lost if you work on
the figure further (including also panning/zooming on a
displayed figure).

Use `.set_tick_params` instead if possible.

Returns
-------
list of `.Text`\s
Expand Down
22 changes: 22 additions & 0 deletions lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,17 @@ def set_thetagrids(self, angles, labels=None, fmt=None, **kwargs):
**kwargs
*kwargs* are optional `.Text` properties for the labels.

.. warning::

This only sets the properties of the current ticks.
Ticks are not guaranteed to be persistent. Various operations
can create, delete and modify the Tick instances. There is an
imminent risk that these settings can get lost if you work on
the figure further (including also panning/zooming on a
displayed figure).

Use `.set_tick_params` instead if possible.

See Also
--------
.PolarAxes.set_rgrids
Expand Down Expand Up @@ -1370,6 +1381,17 @@ def set_rgrids(self, radii, labels=None, angle=None, fmt=None, **kwargs):
**kwargs
*kwargs* are optional `.Text` properties for the labels.

.. warning::

This only sets the properties of the current ticks.
Ticks are not guaranteed to be persistent. Various operations
can create, delete and modify the Tick instances. There is an
imminent risk that these settings can get lost if you work on
the figure further (including also panning/zooming on a
displayed figure).

Use `.set_tick_params` instead if possible.

See Also
--------
.PolarAxes.set_thetagrids
Expand Down