Skip to content

Commit

Permalink
Backport PR matplotlib#26436: DOC: Add a warning that ticks are not p…
Browse files Browse the repository at this point in the history
…ersistent
  • Loading branch information
tacaswell authored and meeseeksmachine committed Aug 2, 2023
1 parent 2ba853d commit 53211a6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
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

0 comments on commit 53211a6

Please sign in to comment.