Skip to content

Commit cb6ae77

Browse files
authored
Merge pull request #17592 from timhoffm/doc-set_useOffset
DOC: Improve docstrings of ScalarFormatter
2 parents 02194b6 + e2bebbe commit cb6ae77

File tree

1 file changed

+83
-5
lines changed

1 file changed

+83
-5
lines changed

lib/matplotlib/ticker.py

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,21 @@ class ScalarFormatter(Formatter):
484484
"""
485485
Format tick values as a number.
486486
487-
If ``useOffset == True`` and the data range is much smaller than the data
488-
average, then an offset will be determined such that the tick labels
489-
are meaningful. Scientific notation is used for ``data < 10^n`` or
490-
``data >= 10^m``, where ``n`` and ``m`` are the power limits set using
491-
``set_powerlimits((n, m))``, defaulting to :rc:`axes.formatter.limits`.
487+
Parameters
488+
----------
489+
useOffset : bool or float, default: :rc:`axes.formatter.useoffset`
490+
Whether to use offset notation. See `.set_useOffset`.
491+
useMathText : bool, default: :rc:`axes.formatter.use_mathtext`
492+
Whether to use fancy math formatting. See `.set_useMathText`.
493+
useLocale : bool, default: :rc:`axes.formatter.use_locale`.
494+
Whether to use locale settings for decimal sign and positive sign.
495+
See `.set_useLocale`.
496+
497+
Notes
498+
-----
499+
In addition to the parameters above, the formatting of scientific vs.
500+
floating point representation can be configured via `.set_scientific`
501+
and `.set_powerlimits`).
492502
"""
493503

494504
def __init__(self, useOffset=None, useMathText=None, useLocale=None):
@@ -514,9 +524,45 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None):
514524
self._useLocale = useLocale
515525

516526
def get_useOffset(self):
527+
"""
528+
Return whether automatic mode for offset notation is active.
529+
530+
This returns True if ``set_useOffset(True)``; it returns False if an
531+
explicit offset was set, e.g. ``set_useOffset(1000)``.
532+
533+
See Also
534+
--------
535+
ScalarFormatter.set_useOffset
536+
"""
517537
return self._useOffset
518538

519539
def set_useOffset(self, val):
540+
"""
541+
Set whether to use offset notation.
542+
543+
When formatting a set numbers whose value is large compared to their
544+
range, the formatter can separate an additive constant. This can
545+
shorten the formatted numbers so that they are less likely to overlap
546+
when drawn on an axis.
547+
548+
Parameters
549+
----------
550+
val : bool or float
551+
- If False, do not use offset notation.
552+
- If True (=automatic mode), use offset notation if it can make
553+
the residual numbers significantly shorter. The exact behavior
554+
is controlled by :rc:`axes.formatter.offset_threshold`.
555+
- If a number, force an offset of the given value.
556+
557+
Examples
558+
--------
559+
With active offset notation, the values
560+
561+
``100_000, 100_002, 100_004, 100_006, 100_008``
562+
563+
will be formatted as ``0, 2, 4, 6, 8`` plus an offset ``+1e5``, which
564+
is written to the edge of the axis.
565+
"""
520566
if val in [True, False]:
521567
self.offset = 0
522568
self._useOffset = val
@@ -527,9 +573,24 @@ def set_useOffset(self, val):
527573
useOffset = property(fget=get_useOffset, fset=set_useOffset)
528574

529575
def get_useLocale(self):
576+
"""
577+
Return whether locale settings are used for formatting.
578+
579+
See Also
580+
--------
581+
ScalarFormatter.set_useLocale
582+
"""
530583
return self._useLocale
531584

532585
def set_useLocale(self, val):
586+
"""
587+
Set whether to use locale settings for decimal sign and positive sign.
588+
589+
Parameters
590+
----------
591+
val : bool or None
592+
*None* resets to :rc:`axes.formatter.use_locale`.
593+
"""
533594
if val is None:
534595
self._useLocale = mpl.rcParams['axes.formatter.use_locale']
535596
else:
@@ -538,9 +599,26 @@ def set_useLocale(self, val):
538599
useLocale = property(fget=get_useLocale, fset=set_useLocale)
539600

540601
def get_useMathText(self):
602+
"""
603+
Return whether to use fancy math formatting.
604+
605+
See Also
606+
--------
607+
ScalarFormatter.set_useMathText
608+
"""
541609
return self._useMathText
542610

543611
def set_useMathText(self, val):
612+
r"""
613+
Set whether to use fancy math formatting.
614+
615+
If active, scientific notation is formatted as :math:`1.2 \times 10^3`.
616+
617+
Parameters
618+
----------
619+
val : bool or None
620+
*None* resets to :rc:`axes.formatter.use_mathtext`.
621+
"""
544622
if val is None:
545623
self._useMathText = mpl.rcParams['axes.formatter.use_mathtext']
546624
else:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy