Skip to content

Commit 7b7ac00

Browse files
committed
Allow base=None to disable log formatter in Continuous.label
1 parent a02b6bf commit 7b7ac00

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

doc/whatsnew/v0.12.1.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ v0.12.1 (Unreleased)
1414

1515
- |Enhancement| |Defaults| Axes with a :class:`objects.Nominal` scale now appear like categorical axes in class seaborn, with fixed margins, no grid, and an inverted y axis (:pr:`3069`).
1616

17-
- |Enhancement| Marks that sort along the orient axis (e.g. :class:`objects.Line`) now use a stable algorithm (:pr:`3064`).
17+
- |Enhancement| |API| The :meth:`objects.Continuous.label` method now accepts `base=None` to override the default formatter with a log transform (:pr:`3087`).
18+
19+
- |Enhancement| |Fix| Marks that sort along the orient axis (e.g. :class:`objects.Line`) now use a stable algorithm (:pr:`3064`).
1820

1921
- |Enhancement| |Fix| Added a `label` parameter to :func:`pointplot`, which addresses a regression in 0.12.0 when :func:`pointplot` is passed to :class:`FacetGrid` (:pr:`3016`).
2022

seaborn/_core/scales.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from pandas import Series
3636

3737
from seaborn._core.rules import categorical_order
38+
from seaborn._core.typing import Default, default
3839

3940
from typing import TYPE_CHECKING
4041
if TYPE_CHECKING:
@@ -494,7 +495,7 @@ def label(
494495
self,
495496
formatter: Formatter | None = None, *,
496497
like: str | Callable | None = None,
497-
base: int | None = None,
498+
base: int | None | Default = default,
498499
unit: str | None = None,
499500
) -> Continuous:
500501
"""
@@ -510,6 +511,7 @@ def label(
510511
and returns a string.
511512
base : number
512513
Use log formatter (with scientific notation) having this value as the base.
514+
Set to `None` to override the default formatter with a log transform.
513515
unit : str or (str, str) tuple
514516
Use SI prefixes with these units (e.g., with `unit="g"`, a tick value
515517
of 5000 will appear as `5 kg`). When a tuple, the first element gives the
@@ -613,7 +615,7 @@ def _get_locators(self, locator, at, upto, count, every, between, minor):
613615
def _get_formatter(self, locator, formatter, like, base, unit):
614616

615617
log_base, symlog_thresh = self._parse_for_log_params(self.trans)
616-
if base is None:
618+
if base is default:
617619
if symlog_thresh:
618620
log_base = 10
619621
base = log_base

tests/_core/test_scales.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ def test_log_tick_count(self, x):
213213
a.set_view_interval(.5, 1050)
214214
assert_array_equal(a.major.locator(), [1, 10, 100, 1000])
215215

216+
def test_log_tick_format_disabled(self, x):
217+
218+
s = Continuous(trans="log").label(base=None)._setup(x, Coordinate())
219+
a = PseudoAxis(s._matplotlib_scale)
220+
a.set_view_interval(20, 20000)
221+
labels = a.major.formatter.format_ticks(a.major.locator())
222+
for text in labels:
223+
assert re.match(r"^\d+$", text)
224+
216225
def test_log_tick_every(self, x):
217226

218227
with pytest.raises(RuntimeError, match="`every` not supported"):

0 commit comments

Comments
 (0)